代碼:阿賈克斯獲得響應不確定的和未捕獲的ReferenceError
query = "http://localhost:8080/working_login.php?name=" + name + "&password=" + pass;
console.log(query);
$.ajax({
type: "GET",
url: query,
dataType: "script",
success: function(data){
console.log(data);
console.log("success");
},
error:function (msg) {
console.log("error on page");
}
});
我收到未定義的數據,因爲我回國在PHP做服務器端「valid_user」,得到錯誤。
Uncaught ReferenceError: valid_user is not defined
(anonymous function)
PHP服務器端代碼:
$sql = "SELECT id FROM users WHERE name ='$name' AND password = '$password';";
$result = mysql_query($sql) or die('Can not Register user' . $sql);
$rows = mysql_num_rows($result);
if($rows > 0)
{
echo("valid_user");
exit();
}
else
{exit("not valid user");}
? – DCoder
@DCoder所以我應該使用什麼?當我使用腳本時,它會成功,否則會在頁面上出錯。 – kamil
向我們展示服務器發回的內容 – Popnoodles