2

I try to send file to remote server by jQuery/AJAX. When I try use postman, it's ok, but when I try do in by jQuery, I get error:

XMLHttpRequest cannot load http://... . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '...' is therefore not allowed access. The response had HTTP status code 400.

My code looks like(get it from postman):

var form = new FormData();
                form.append("file", {"0": item[0].files[0]});

                var settings = {
                  "async": true,
                  "crossDomain": true,
                  "url": url,
                  "method": "POST",
                  "headers": {
                  },
                  "processData": false,
                  "contentType": false,
                  "mimeType": "multipart/form-data",
                  "data": form
                }

                jQuery.ajax(settings).done(function (response) {
                  console.log(response);
                });

see logs here: http://pastebin.com/DvhTxVSw

So, how can I make an api request from client side, with jquery, to another server(where the web page is not hosted)?

DontVoteMeDown
  • 21,122
  • 10
  • 69
  • 105
  • Possible duplicate of ["No 'Access-Control-Allow-Origin' header is present on the requested resource"](http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource) – Hanky Panky Aug 31 '16 at 17:23
  • If you have control over the API, you should add `Access-Control-Allow-Origin` to the response, as the error shows. – DontVoteMeDown Aug 31 '16 at 17:24
  • @DontVoteMeDown we have added this on server side. As you can see, with `postman` it works fine, but with the js as written above, it doesn't work. – Filip Luchianenco Aug 31 '16 at 17:35
  • @HankyPanky we are using `CORS` – Filip Luchianenco Aug 31 '16 at 17:36

0 Answers0