尽管将方法设置为POST,服务器仍继续将来自我的AJAX方法的任何请求视为GET请求。知道为什么会这样吗?
function postToServer(firstName, lastName, emailAddress, feedback) {
console.log(firstName, lastName, emailAddress, feedback);
$.ajax({
method: "POST",
url: " http://xxxxxx.com/postto",
data: "",
dataType: "json",
success: function(data) {
console.log(data);
}
});
}
答案 0 :(得分:1)
没有选项调用method:
type:
function postToServer(firstName,lastName,emailAddress,feedback){
console.log(firstName, lastName, emailAddress,feedback);
$.ajax({
type: "POST",
url: " http://xxxxxx.com/postto",
data: "",
dataType: "json",
success: function(data){
console.log(data);
}
});
}
答案 1 :(得分:0)
正确的语法是
type : 'POST'
而不是
method : 'POST
答案 2 :(得分:-1)
试试这个
$.post( "http://xxxxxx.com/postto", "", function(data) {
console.log(data);
}, 'json');