Ajax: Response for preflight has invalid HTTP status code 404

给你一囗甜甜゛ 提交于 2019-12-11 04:49:09

问题


I have services and when i call it
I get error, Response for preflight has invalid HTTP status code 404 as shown in below picture. please here me to solve this problem Thank you

Here is 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>

回答1:


This worked for me:

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

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

  })
});


来源:https://stackoverflow.com/questions/47252264/ajax-response-for-preflight-has-invalid-http-status-code-404

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!