【问题标题】:Ajax: Response for preflight has invalid HTTP status code 404Ajax:预检响应具有无效的 HTTP 状态代码 404
【发布时间】:2018-04-25 10:09:14
【问题描述】:

我有服务,当我调用它时
我收到错误,预检响应具有无效的 HTTP 状态代码 404,如下图所示。 请在这里解决这个问题 谢谢

这里是ajax

    $.ajax({
        url:url,
        type: "Get",
        async: true,
        contentType: "application/text",
        dataType: "json",
        cache: false,
        crossDomain: true,
        success: function (data) {

        }

        }
    });

Web.config

 <system.webServer>
 <httpProtocol>
      <customHeaders>
        <remove name="X-Powered-By" />
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Accept, Content-Type, Origin" />
        <add name="Access-Control-Allow-Methods" value="GET, PUT, POST, DELETE, OPTIONS" />
      </customHeaders>
    </httpProtocol>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
    </security>
    <modules>
      <remove name="FormsAuthentication" />
    </modules>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>

【问题讨论】:

  • 我有同样的问题。这个问题你解决了吗?

标签: jquery ajax asp.net-mvc asp.net-web-api2


【解决方案1】:

这对我有用:

var settings = {
  "async": false,
  "url": url,
  "dataType": "json",
}

$.ajax(settings).done(function(response) {
  $.each(JSON.parse(response), function(index, item) {

  })
});

【讨论】:

  • 虽然这段代码可以回答问题,但最好解释一下如何解决问题,并提供代码作为示例或参考。仅代码的答案可能会令人困惑且缺乏上下文。
猜你喜欢
  • 2017-09-26
  • 2016-01-22
  • 2018-10-19
  • 2016-05-21
  • 2017-12-22
  • 1970-01-01
  • 2018-03-12
  • 2016-02-13
  • 2016-01-18
相关资源
最近更新 更多