以下代码完美无缺:
function callWebhookAndShowCart(element) {
$.ajaxSetup({
xhrFields: {
withCredentials: true
}
});
var webHook = $(element).attr('webHook');
var webParams = $(element).attr('webParams');
if (webHook) {
$.ajax({
url: webHook,
data: webParams,
dataType: 'json',
crossDomain: true,
success: function(cart) {
getCartRendering(cart);
},
error: function() {
console.log('error');
}
});
}
}
但是以下操作不起作用并返回method not allowed
:
function callWebhookAndShowCart(element) {
$.ajaxSetup({
xhrFields: {
withCredentials: true
}
});
var webHook = $(element).attr('webHook');
var webParams = $(element).attr('webParams');
if (webHook) {
$.ajax({
type: "POST",
url: webHook,
data: webParams,
dataType: 'json',
crossDomain: true,
success: function(cart) {
getCartRendering(cart);
},
error: function() {
console.log('error');
}
});
}
}
唯一的变化是从GET
转换为POST
。响应头中显示的服务器配置是:
Response Header
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:x-requested-with, Content-Type, X-PINGOTHER, x-requested-by, Content-length, Connection
Access-Control-Allow-Methods:POST, GET, HEAD, OPTIONS, PUT, DELETE
Access-Control-Allow-Origin:http://localhost:8080
Access-Control-Max-Age:3600
Content-Encoding:gzip
Content-Type:text/html;charset=utf-8
Date:Thu, 15 Dec 2016 08:39:03 GMT
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked
Vary:Accept-Encoding
请帮助,因为我不确定服务器配置需要更改什么才能使用。