-1

I try to send request to an API in remote server.

  $.ajax({
                type: "POST",
                url: "http://myserverIPAddress/myAPIPath.aspx/FunctionName",
                data: "{myID :7 }",            
                contentType: "application/json; charset=utf-8;",
                dataType: "json",
                success: function (response) {
                    debugger;

                },
                error: function (response, res, r) {

                    debugger;
                }
            });

the request fail and I get this error:

Failed to load resource: the server responded with a status of 404 (Not Found) XMLHttpRequest cannot load http://myserverIPAddress/myAPIPath.aspx/FunctionName. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:5316' is therefore not allowed access. The response had HTTP status code 404.

Thank for help.

Efrat
  • 27
  • 1
  • 8

1 Answers1

0

You've been hit with the same-origin policy. Basically what's happening is that the remote server has not set a proper header on the content you are requesting and you cannot load it in your page. To load data from a remote server (called a Cross Origin Request- CORS), the server operator will need to add the "Access-Control-Allow-Origin" header to their content. More info here.

rioc0719
  • 303
  • 2
  • 11