Javascript AJAX-JSON错误
当我试图从服务器端接收数据时,出现以下错误: 06-30 11:23:57.119:I/chromium(7486):[信息:控制台(50)]“{“readyState”:4,“responseText:”“status”:404,“statusText:”“Not Found”}”,来源:file:///android_asset/www/js/index.js (50) JS文件:Javascript AJAX-JSON错误,javascript,php,jquery,ajax,json,Javascript,Php,Jquery,Ajax,Json,当我试图从服务器端接收数据时,出现以下错误: 06-30 11:23:57.119:I/chromium(7486):[信息:控制台(50)]“{“readyState”:4,“responseText:”“status”:404,“statusText:”“Not Found”}”,来源:file:///android_asset/www/js/index.js (50) JS文件: $j.ajax({ type: 'POST', url: 'http://www.myra
$j.ajax({
type: 'POST',
url: 'http://www.myrandomurl.com/SupportData/login.php',
crossDomain: true,
data: {email: e, password :p},
dataType: 'json',
async: false,
success: function (response){
//alert ("response");
//alert(JSON.stringify(response));
//console.log(JSON.stringify(response));
if (response.success) {
myApp.alert("you're logged in");
//window.localStorage["email"] = e;
//window.localStorage["password"] = p;
console.log(window.localStorage["email"]);
//localStorage.removeItem('email');
mainView.router.loadPage('main.html');
} else {
myApp.alert("Your login failed");
//window.location("main.html");
}
},
error: function(error){
//alert(response.success);
//myApp.alert('Could not connect to the database' + error);
console.log(JSON.stringify(error));
//window.location = "index.html";
}
});
PHP方面:
$sql = "SELECT login_id, email_id, password FROM login WHERE email_id='$myusername' and password='$mypassword'";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
$row = mysql_fetch_array($result);
if($num_rows == 1) {
$response['success'] = true;
}else {
$response['success'] = false;
}
echo json_encode($response);
正如您在
控制台
中看到的,您得到了404
,这意味着您的URL不正确。我可以直接访问URL,直接访问时我得到{“success”:false}