0

I am trying to call an api with some required data.My request hits the server successfully

Diljit PR
  • 301
  • 3
  • 14
  • possible duplicate of [jQuery AJAX cross domain](http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain) – Diljit PR Oct 26 '14 at 09:50

1 Answers1

1

Cross-Origin (Ajax) requests to other domains are normally blocked by browsers due to security reasons (eg: to prevent CSRF attacks). When a response comes from the server for a Cross-Origin (Ajax) request, browser checks if the response comes from the same domain. If it comes from the same domain browser accepts the response. Otherwise the browser checks for the header "Access-Control-Allow-Origin: *". This header is set from the server if they allow Cross-Origin (Ajax) requests.

Your API seems to be not allow Cross-Origin requests. Some APIs allow this..

As an alternative you can access the API from your server, and send the response to the client from your server. (Eg. if your server is php you can use "file_get_contents('http://www.example.com/')" to access the API from the server). Also try changing the Post request to Get if possible...

Sampath Liyanage
  • 4,776
  • 2
  • 28
  • 40