[英]No form data when while posting an array using AJAX
I am currently using the following code to try and post an array using AJAX, however console
shows no Form Data section when checking the Headers. 我目前正在使用以下代码尝试使用AJAX发布数组,但是在检查Header时console
显示Form Data部分。
$(document).on("click", "#saveB", function () {
var qry_array = [];
var qry = query();
var key = $('#save_key').val();
qry_array[key]=qry;
console.log(qry_array);
$.ajax({
type: "POST",
url: "favourites.php",
data: {
query: qry_array
},
success: function (response) {
console.log (response);
}
});
});
favourites.php favourites.php
error_reporting ( E_ALL );
ini_set ( 'display_errors', 1 );
function saveQueries() {
if (isset ( $_POST ['query'] )) {
$arr = $_POST['query'];
var_dump($arr);
} else {
echo "Key Missing";
}
}
saveQueries ();
The response from console
is Key Missing
which means my query
isn't being posted, why could this be?? console
的响应是“ Key Missing
,这意味着我的query
未发布,为什么会这样?
Try using $.post() instead: 尝试使用$ .post()代替:
$.post("favourites.php", { query: qry_array }).done(function(response) {
console.log (response);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.