跳轉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; } }}