跳轉-ajax phonegap 和 RESTful Codeigniter 問題

來源:互聯網
上載者:User
關鍵字 跳轉 ajax js php
跳轉ajaxjsphp

大家好 我現在準備用phonegap做一個安卓的app 現在需要做一個登入介面 有使用者名稱密碼 和提交按鈕 當點擊提交按鈕 用ajax發送資料給 後台伺服器 然後伺服器返回true或者是false 如果是true跳入另外一個介面 如果是 false 彈出對話方塊提醒 現在問題是點擊提交的時候一直顯示ajax的error裡面的 failed login。我覺得應該是url的問題 可是找了很久也不知道如何改:

ajax代碼:
<

script type="text/javascript">           $(document).ready(function()             {                $('#submit').click(function()                {                //Get data-theme data from all fields                var username = $('#username').val();                var password = $('#password').val();                //Username and password can not be empty                if(username =='')                {                    alert('Please enter your username!');                    return false;                }                if(password =='')                {                    alert('Please enter your password!');                    return false;                }                var form_data =                 {                    'username': username,                    'password': password                };                //ajax code start here                $.ajax              ({                    url: 'http://localhost/restserver/index.php/api/apiauth/auth',                                        data: form_data,                     type: 'POST',                    cache: false,                        dataType: "json",                    error: function(XMLHttpRequest, textStatus, errorThrown)                    {                        alert('Failed to login');                        console.log(JSON.stringify(XMLHttpRequest));                        console.log(JSON.stringify(textStatus));                        console.log(JSON.stringify(errorThrown));                    },                    success: function (data)                {                    alert("Success login");                        //$.mobile.changePage("index.html", "slideup");                }             });                      return false;               });         });             

html部分:

                                    Username                                                                            password                                                                            Login                                                

後台RESTful CI:

load->model('membership_model');      $query=$this->membership_model->validate();      $this->response($query,200);    }}db->where('username',$this->input->post('username'));        $this->db->where('password',$this->input->post('username'));        $query=$this->db->get('membership');        if($query->num_rows=1)        {            return true;        }        else        {            return false;        }    }}
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.