我有一个调用WCF服务的ajax代码,当我通过localhost调用它时,它说Failed to load resource:http://servicelink?order%5B0%5D%5BCoupanId%5D=1&order%5B0%5D%5BDiscount%5D=1&order%5B0%5D%5BEmailAddress%5D=em.com&order%5B0%5D%5ailtemName%5D=Sgfa+wraps&order%5B0%5D%5BItem_Id%5D=1&order%5B0%5D%5BQty%5D=1&order%5B0%5D%5Bprice%5D=5.5 the server responded with a status of 405 (Method Not Allowed)
但它需要所有参数。当我通过更改为POST将上面显示的相同链接显示在Postman的片段中时,它可以正常工作。
我已将此更改为也在localhost问题上POST仍然存在。
答案 0 :(得分:1)
你可以改变这个:contentType: "application/x-www-form-urlencoded"
我得到了回应:
jQuery.support.cors = true;
$.ajax({
url: "http://service link",
type: "POST",
dataType: "json",
contentType: "application/x-www-form-urlencoded",
// data: { order: orderData },
success: function (response) {
alert(response.OrderPlacementResult);
// orderId = data;
if (data != null) {
orderStatus = "Order has been placed successfully.";
}
}
});
从你这边尝试