[Vuejs]-Axios post request failing due to CORS but the same request using ajax is getting no issues

0👍

This issue arises because jQuery sends the request as application/x-www-form-urlencoded by default and does not send preflight request whereas axios sends as application/json and sends a preflight request i.e. OPTIONS before sending actual request.

One way it could work is by setting Content-type header to 'Content-Type': 'application/x-www-form-urlencoded' in axios.

You will have to change the settings on server side to get around this issue.

0👍

Add this in your web.config file:

<system.webServer>
  <handlers>
    <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
    <remove name="OPTIONSVerbHandler" />
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
  </handlers>
</system.webServer>

Using default ajax won’t send any OPTIONS request, but using axios does. This will enable accepting OPTIONS requests.

Leave a comment