0

i have an Postman API and its working in postman but i want to run it in javascript and get the return values but there's an error im encountering

No 'Access-Control-Allow-Origin' header is present on the requested resource

i research and it is said it is caused by the CORS, how can i implement/bypass it in javascript?

    $( document ).ready(function() {
    $.ajax({
             method: "POST",
             contentType: "application/json",
             url: "https://dev.mysample.com/api/v1/Access",
             data: { ClientID: "myID", ClientSecret: "password", GrantType: "mycredentials"}
         }).done(function( msg ) {
            console.log(msg);
         }).fail(function( msg ) {
            console.log(msg);
         });
    });

im using asp classic as my server side language

coriano35
  • 165
  • 1
  • 3
  • 10
  • 2
    As is explained in the other CORS questions here on stackoverflow, you cannot bypass that. If you don't control `dev.mysample.com`, the only thing you can do is make a request to your own server and have your server make the request to the 3rd party server. –  Oct 18 '18 at 01:05

1 Answers1

1

Actually this is something you should implement in your server. In that warning message the "requested resource" is the url you're requesting and you're requesting it to your server, so it should add the 'access-control-allow-origin' header. Anyway, there are some ways in certain situations where you can bypass it.

Ways to circumvent the same-origin policy

Giacomo Cerquone
  • 2,352
  • 5
  • 24
  • 33