简体   繁体   中英

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

I have use the rest API to load my Json data in another iis server. The allow-access control origin already can work fine. But it just for the get method.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpProtocol>
   <customHeaders>
   <add name="Access-Control-Allow-Origin" value="*" />
   <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE" />
   <add name="Access-Control-Request-Methods" value="GET, POST, PUT, DELETE" />
   <add name="Access-Control-Allow-Headers" value="X-Requested-With,Access-Control-Request-Method,Access-Control-Request-Headers, accept, Content-Type" /> 
   <add name="Access-Control-Request-Headers" value="X-Requested-With,Access-Control-Request-Method,Access-Control-Request-Headers, accept, Content-Type" /> 

   </customHeaders>
 </httpProtocol>

</system.webServer>
</configuration>

After for the put or delete or update method, it occurs

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

error.

               $.ajax({
                    type: 'PUT',
                    xhrFields: {
                      withCredentials: false
                    },
                    contentType: 'application/json',
                    url: rootURL,
                    dataType: "json",
                    data: editFormToJSON6(),
                    success: function(data){

                    },
                    error: function() {
                    }
                });

Add options routes to every route contained in your API, also credentials should be always set to true.

At the server side make sure options response responds with a 200 status code each time a request is made.

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