Post JSON ajax request with cors not working in IE10/Edge

后端 未结 2 1697
误落风尘
误落风尘 2021-02-07 08:21

Background:- I created a WCF service hosted in my local system IIS. Service exposes GET/POST method and cross domain enabled and can be accessed using https too

相关标签:
2条回答
  • 2021-02-07 09:22

    There are a few things you can check client-side:

    • you're trying to override $.support.cors. This is (or was) meant to be a readable property telling you if CORS is supported by the browser. (see jQuery source for where this is checked)
    • Based on jQuery docs for ajax you might want to add xhrFields: { withCredentials: true } to the $.ajax() options
    • Use correct casing of dataType: "json" and charset=UTF-8

    At server-side, you may want to try responding with specific hostname (echo the Origin header) instead of wildcard (*) in the Access-Control-Allow-Origin response header. This is specifically mentioned in MDN in a paragraph also discussing Access-Control-Allow-Credentials:

    Important note: when responding to a credentialed request, server must specify a domain, and cannot use wild carding. The above example would fail if the header was wildcarded as: Access-Control-Allow-Origin: *.

    0 讨论(0)
  • 2021-02-07 09:27

    It's not a long term solution, but you could check out https://cors-anywhere.herokuapp.com/ You can GET or even POST data without issue through this. Include their link before your URL so https://cors-anywhere.herokuapp.com/http://ateet3371/Service1.svc/postdata and set that as the URL value in your ajax. Like I said, it's not a long term solution but if it works then see what you can do from there.

    I wish I could be of more assistance. Good luck!

    0 讨论(0)
提交回复
热议问题