简体   繁体   中英

Unable to make ajax request to remote server from localhost

I am making an ajax request (with jquery) from my local server to a remote page (which I am the admin) and I get

 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://ica.local.com' is therefore not allowed access. The response had HTTP status code 405.

This is how my request looks like:

$.ajax({
  url:  myurl,
  type: "POST",
  // This is the important part
  xhrFields: {
    withCredentials: true
  },
  // This is the important part 
  success: function (response) {
    // handle the response
  },
  error: function (xhr, status) {
    // handle errors
 }
});

The application on the remote server is running on nginx server. I tried to change the conf file of nginx to Access-Control-Allow-Origin: * but it still doesnt work.

It is because both the machines are on different servers. For development purpose you can use chrome extensions already available to fix the purpose.

Just search 'Cross origin issue' on chrome extension page and then include one of extensions

Try to create a sample server file like php and call the remote with curl from php. Than return the response as json to your is

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM