【问题标题】:Code work with Postman but not at localhost Ajax代码可以与 Postman 一起工作,但不能在 localhost Ajax 上工作
【发布时间】:2016-08-19 06:01:49
【问题描述】:

我有一个调用 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 的 sn-p 中显示与上面相同的链接时,它工作正常。 我已将其更改为在本地主机上也 POST 问题仍然存在。

【问题讨论】:

  • 它的405响应权。您是否在邮递员中提供了任何身份验证或令牌?
  • 是的,它的 405。No Auth 与邮递员
  • 检查了标题?
  • @Rigin 在没有身份验证的情况下在邮递员中尝试相同的链接,它可以工作

标签: jquery ajax wcf postman html-framework-7


【解决方案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."; 
} 
} 

});

从你身边尝试

【讨论】:

  • 知道了,伙计。谢谢x
  • 无论如何都很好。我在聊天中失去了你
猜你喜欢
  • 1970-01-01
  • 2019-06-16
  • 1970-01-01
  • 1970-01-01
  • 2020-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-31
相关资源
最近更新 更多