嗨嗨在我的ajax函數上使用json檢索數據時出現此錯誤。它不會返回任何數據。這裏是我的代碼如下我的jQuery ajax json函數的錯誤,不會返回數據
$.ajax({
url: "php/getCategory.php?action=getyear",
cache: false,
dataType: "json",
success: function(data){
$.each(data.items, function(i,item){
$("#catYear").append('<option value="'+item.id+'">'+item.name+'</option>');
});
}
});
當我嘗試刪除dataType:「json」它將傳入成功:函數。我認爲問題出在我的json上。我也迴應我的getCategory.php的輸出,我認爲他們沒有問題。以下是我的php json_encode的輸出。
{items:[{"id":"1","name":"2010"},{"id":"2","name":"2011"}]}
謝謝!
是PHP用JSON頭輸出? – dotty 2011-04-19 07:57:01
@dotty ...你是什麼意思,對不起,即時新的這個..你可以給我例子。謝謝! – andsien 2011-04-19 07:58:52
@dotty ...我使用json_encode。我認爲沒有必要把它放在我的標題上。我對麼? – andsien 2011-04-19 08:02:08