Postman可以使用,但本地主机上的Ajax代码无法工作

4

我有一段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)”,但是它仍然将所有参数传递过去。当我在Postman中使用相同的链接并将其更改为POST时,它正常工作。我已经将其更改为POST,但在本地主机上仍然存在问题。


你的405响应没问题。你在Postman中提供了任何身份验证或令牌吗? - Rigin
检查了头文件吗? - Rigin
@Rigin,请尝试在Postman中使用相同的链接进行请求,不需要身份验证,它可以正常工作。 - Mangrio
在哪里可以检查头文件? - Mangrio
1
让我们在聊天中继续这个讨论 - Rigin
显示剩余3条评论
1个回答

2

请将此更改为:contentType: "application/json"

我得到了以下响应:

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."; 
} 
} 

});

请从您的角度尝试


明白了,伙计。谢谢。 - Mangrio
不管怎样,很好。我在聊天中失去了你。 - Rigin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接