function handleLogin() {
var fnUrl = base_url+"auth/mob_log";
var form = $("#loginForm");
var u = $("#username", form).val();
var p = $("#password", form).val();
if(u != '' && p!= '') {
$.ajax({
url: fnUrl,
data: {"u": u,"p":p}, //returns all cells' data
dataType: 'json',
type: 'POST',
success: function (res) {
if (res.log == '1') {
window.localStorage["username"] = u;
window.localStorage["password"] = p;
checkLoginAuth();
} else{
alert(res.msg)
$("#edLogin").removeAttr("disabled");
}
},
//this errormsg is showing while login
error: function () {
alert('Something went wrong.Contact Support')
}
});
}
else {
alert("Enter Username and Password")
$("#edLogin").removeAttr("disabled");
}
return false;
}
PHP
function mob_log() {
$username = $this->input->post('u');
$password = $this->input->post('p');
$login_result = $this->ion_auth->login_mob($username,$password);
if($login_result == 1)
{
$this->load->model('login_model');
$p_details=$this->login_model->get_p_details($this->input->post('u'));
$p_id = $p_details->id;
$out = array(
'log' => '1',
'p_id' => $p_id,
'msg'=>'Logged in'
);
echo json_encode($out);
}
else
{
$out = array(
'log' => '0',
'msg'=>'Unable to login'
);
echo json_encode($out);
}
}
答案 0 :(得分:0)
试试这个:
var data = "u": u,"p":p};
$.post(fnUrl, data)
.done(function (res) {
alert(res);
res = $.parseJSON(res);
if (res.log == '1') {
window.localStorage["username"] = u;
window.localStorage["password"] = p;
checkLoginAuth();
} else{
alert(res.msg)
$("#edLogin").removeAttr("disabled");
}
});
此外,使用console.log和alert函数来跟踪值的内容。