我正在尝试使用whcms中的ajax发送post请求,但似乎来自ajax请求的数据为null。
这是ajax请求:
cpp -o external.o
In file included from external.cpp:8:0:
predModule.h:12:23: fatal error: RcppEigen.h: No such file or directory
compilation terminated.
/usr/lib64/R/etc/Makeconf:139: recipe for target 'external.o' failed
make: *** [external.o] Error 1
ERROR: compilation failed for package ‘lme4’
并在我的php文件中:
function send_request(ticket_or_credit){
if(ticket_or_credit == 'ticket'){
var url = $("#ticket_action").val();
var ticket = $("#ticket_ticket").val();
var solution = $("#ticket_solution").val();
whmcs_data={ request_type:ticket, solution:solution };
jQuery.ajax({
type: 'POST',
url: url,
data: JSON.stringify(whmcs_data),
contentType:"application/json; charset=utf-8",
dataType: 'json',
success: function(results){
console.log(results);
console.log(whmcs_data);
},
error( xhr, ajaxOptions, thrownError ){
console.log( thrownError );
}
});
}
}
$ _POST为空。
请帮助我,我没有解决这个问题多少天:(
答案 0 :(得分:1)
我删除了ajax代码的contentType
和dataType
,只是为了使其默认application/x-www-form-urlencoded; charset=UTF-8')
并正确序列化whmcs_data
变量。 JSON.stringify的输出未正确序列化,因此我手动序列化它。有关ajax的更多信息请访问:http://api.jquery.com/jquery.ajax/和JSON.stringify - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
尝试用以下代码替换变量whmcs_data
声明和ajax代码:
whmcs_data = {
"request_type": ticket,
"solution": solution
};
$.ajax({
type: 'POST',
url: url,
data: whmcs_data,
success: function(results){
console.log(results);
console.log(whmcs_data);
},
error( xhr, ajaxOptions, thrownError ){
console.log( thrownError );
}
});