代码适用于 Postman 但不适用于 localhost Ajax
Code work with Postman but not at localhost Ajax
我有一个代码 ajax 正在调用 WCF 服务,当我通过本地主机调用它时它显示 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 将上面显示的相同 link 放在 Postman 的代码片段中时,它工作正常。
我已将其更改为 POST at localhost 问题仍然存在。
你能改变这个吗: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.";
}
}
});
从你这边试试
我有一个代码 ajax 正在调用 WCF 服务,当我通过本地主机调用它时它显示 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 将上面显示的相同 link 放在 Postman 的代码片段中时,它工作正常。
我已将其更改为 POST at localhost 问题仍然存在。
你能改变这个吗: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.";
}
}
});
从你这边试试