當我嘗試從JSON響應中獲取值時,我彈了起來。這裏是我的代碼如何從AJAX響應中檢索JSON變量
代碼:
$.ajax({
url: 'checkvotes.php',
dataType: "json",
success: function(data) {
// want to fetch UP and DOWN variables from JSON here
}
});
AJAX從PHP
{"sample":[{"id":"1","message":"my message","up":"200","down":"34"}]}
你試過了什麼? – Quentin 2010-10-07 12:42:38
alert(data.id);其中說undefined – Rajasekar 2010-10-07 12:45:35
該對象沒有id屬性,它只有一個示例屬性(其長度爲1的數組作爲其值... – Quentin 2010-10-07 12:50:39