0

I'm calling asmx API from webpage using of Ajax call, But I'm getting "Access to XMLHttpRequest at 'url' from origin 'http://localhost:XXXXX' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header" Error even though I added Header to allow the Origins.Below is the code I have used to call the API. $.ajax({ url: 'url', type: "POST", crossDomain: true, dataType: "xml", contentType: "text/xml; charset=utf-8", headers: { "Access-Control-Allow-Headers": "", "Access-Control-Allow-Origin": "", }, data: soapXMLData,
success: function (data) { alert("webmethod call success"); }, error: function (err) { alert("webmethod call failed"); } });

  • You need to allow anonymous options requests in your server side. – Eldar Jul 19 '20 at 12:17
  • Welcome to Stack Overflow! Please take the [tour] (you get a badge!), have a look around, and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) I also recommend Jon Skeet's [Writing the Perfect Question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/). Please [search](/search?q=Access+has+been+blocked+by+CORS+policy) before posting. More about searching [here](/help/searching). Your **client-side** code can't self-authorize like that. – T.J. Crowder Jul 19 '20 at 12:20
  • Hey Eldar, I'm using asp.net application and I have done that change, Can you share me the peace of code for It. Thanks for the Answer.. Thank you. – Chathilla. Vikram Jul 19 '20 at 13:01

0 Answers0