我正在使用 jQuery ajax 向 PHP Controller 发出 AJAX 请求,但是当尝试使用 PHP 获取发布的数据时,$_POST 为空。下面是实际的功能:
function GetSeriesForManufacturer(manuf) {
selectedmanufacturer = manuf;
//Make an AJax Call For Getting Series Of Manufacturer
var series = null;
$.ajax({
type: "POST",
url: url,
data: "{manufacturer:'" + selectedmanufacturer + "'}",
contentType: "application/json", //; charset=utf-8",
dataType: "json",
cache: false,
async: false,
success: function (response) {
//remove loading gif
$(".loading").hide();
//Append Data
AppendSeries($.parseJSON(response.text), selectedmanufacturer);
//Custom Scrollbar Call
$('.MatchingSeries ul').mCustomScrollbar();
},
error: function (XMLHttpRequest, textStatus, errorThrown) { }
});
}
提前致谢!
最佳答案
首先,您不需要对数据进行字符串化。只需发送对象文字即可。
data: {manufacturer: selectedmanufacturer},
第二,你不需要这一行:
contentType: "application/json",
关于javascript - 服务器端 AJAX post 为空(PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27272730/