2
首先我想描述什麼是錯的。jquery AJAX取代香草js難度
這是我的JQuery代碼,它很好。
$.ajax({ url: 'ajaxHandler.php',
data: {'list' : 'list'},
type: 'post',
dataType:'json',
success: function(output) {
alert(output);
},
error: function(request, status, error){
alert("Error: Could not delete");
}
});
但問題是它我只是想在香草js中創建相同的。
var request = new XMLHttpRequest();
request.open("POST", url, true);
//Send the proper header information along with the request
request.setRequestHeader("Content-type", 'application/json; charset=UTF-8');
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
alert(request.responseText);
};
}
var dataParam = {
'list': 'list'
};
var $json = JSON.stringify(dataParam);
request.send($json);
是誰能告訴我哪裏是我的錯誤。
<?php
require_once 'tasksController.php';
$dataFunction = (string)($_POST['list']);
echo $dataFunction;
?>
這是我的警告: 注意:未定義指數:名單在C:\ XAMPP .......... \ ajaxHandler.php上線3
'JSON.stringify(dataParam)'的輸出是什麼?嘗試''console.log()''它。 – Daniel
[使用XMLHttpRequest發送POST數據]的可能重複(https://stackoverflow.com/questions/9713058/send-post-data-using-xmlhttprequest) –
如果您不需要IE11,則始終會提取。 http://caniuse.com/#search=fetch,並有ie11的polyfills。 – mkaatman