The following code works perfectly fine:
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');
}
});
}
}
However the following does not work and returns 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');
}
});
}
}
The only change is converting from GET
to POST
. The server configuration as evident from the response header is:
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
Please help as I am not sure what needs to be changed for the server configuration for this to work.