简体   繁体   中英

XMLHttpRequest cannot load URL. Response for preflight has invalid HTTP status code 404

I have created a CORS request from my .aspx page. My Ajax request as follows.

$.ajax({
    method: 'POST',
    url: "https://api.kraken.io/v1/url",
    data: JSON.stringify('{"auth": {"api_key:"' + api_key + '","api_secret:"' + API_Secret + '"},"url:"+ "http://test.pw.com/ScreenShots/3C65B6.jpg","callback_url:"+ "http://test4.pw.com/Admin/TaskAndProjectSearch.aspx","json": true}'),
    crossDomain: true,
    beforeSend: function (xhrObj) {
        xhrObj.setRequestHeader("Content-Type", "application/json");
    },
    success: function (result) {
        console.log(result.d);
    },
    error: function (req, status, error) {

    }
});

I am using IIS8 and I have enabled CORS by adding following to web.config

<system.webServer>
    <httpProtocol>
        <customHeaders>
            <add name="Access-Control-Allow-Origin" value="*" />
            <add name="Access-Control-Allow-Methods" value="GET,POST,OPTIONS" />
            <add name="Access-Control-Allow-Headers" value="Content-Type, Access" />
        </customHeaders>
    </httpProtocol>
</system.webServer>

Still I got the following error . XMLHttpRequest cannot load url. Response for preflight has invalid HTTP status code 404 . Have anyone got any idea about this.I need this to be fixed as soon as possible. Please help. Thanks in advance

I was getting this same error just a few minutes ago. Turns out the URL my api was posting to was wrong. When I fixed that, everything worked fine. Make sure your URL is correct.

You have uncorrect web.config content. You should close the <httpProtocol> tag before </system.webServer> . Without that, your application won't even start...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM