我想使用ajax()
函數將JSON變量和整數發送到頁面並追加檢索到的數據。這是我在此刻:jQuery - 如何進行ajax POST調用並追加數據
$.ajax({
type: "POST",
dataType: "json",
url: "get_theme.php",
data: {themestack:themes, iterator:theme_max_iterator},
success: function(data){
alert('Items added');
$("#themes").append(data);
++IFRAMES_IN_DOM;
++theme_max_iterator;
},
error: function(e){
alert(e.message);
}
});
themes
是JSON
變量,theme_max_iterator
是int
。目前,我收到的只是"undefined"
的提醒,所以我想知道什麼是錯的?
編輯:
在日誌文件中,我可以看到從get_theme.php
錯誤:
PHP Warning: json_decode() expects parameter 1 to be string, array given
導致這種結果是該行:
$obj = $_POST['themestack'];
$json_data = json_decode($obj, true);
因爲JSON
這是奇怪的變量themestack
是JSON
。
它可能會去錯誤的功能。所以你的'get_theme.php'返回一個錯誤 – anurupr
檢查你的get_theme.php是否發送了正確的響應。 – Abhidev