我無法得到響應,從一個jQuery Ajax調用回...jQuery的獲得陣列的詳細信息
(這是一個腳本來驗證用戶身份,並需要返回他們的名字和用戶ID。我的理解是我可以對其進行編碼,如JSON和下面的格式獲取數據。
它的警報()。
的JavaScript
返回的「不確定」的錯誤$.ajax({
type: "POST",
url: "myURL.php",
data: {username: username, password: password},
success: function(results) {
//THIS IS WHERE THE PROBLEM IS
alert('Hi '+results.name); //Should be "Hi Basil Fawlty"
}
});
的PHP(myURL.php)
//This comes from a SQL call that returns the following name
json_encode(array(
'id'=>1,
'name'=>'Basil Fawlty'
));
在哪裏我錯了,將不勝感激任何幫助或想法!
謝謝。
解決方案:解決方案是添加dataType。
您使用的是哪個版本的jQuery? – webbiedave 2010-04-26 18:10:55
你可以在這裏發佈你的** alert(results.responceText)**嗎? – 2010-04-26 19:10:21
我使用的是1.3版本。 輸出「未定義」 – Matt 2010-04-27 03:26:22