0

I am trying to make following ajax request:

                                    $.ajax({
                                    method: "GET",
                                    url: http://google.com,
                                    dataType: "json",
                                    async: false,
                                    cache: false,
                                    success: function(data) {
                                    alert("AJAX call successfully 
                                    completed");}});

But as expected, I am getting "Cross-Origin" error. Is there any way to bypass this security and make the ajax call without this error even if ajax call is being made from different domain.

Any response is appreciated.

  • 1
    yes, using proxy server. Create a server/api in your domain and make your request to that server, the server will get cross domain data and send you back – Priyesh Kumar May 23 '17 at 13:06
  • Without alternations to the server you're trying to query (which I presume isn't Google) - no. You could see if JSONP requests are handled by them, else you're out of luck unless you can get them to open up the cross domain policies. The suggestion by @PriyeshKumar would probably work - but feels horribly underhand. – Tom May 23 '17 at 13:07
  • Possible duplicate of [Loading cross domain endpoint with jQuery AJAX](https://stackoverflow.com/questions/15005500/loading-cross-domain-endpoint-with-jquery-ajax) – crizzis May 23 '17 at 13:14
  • @thebluefox right,!. Making small api will take hardly 25 lines ^_^ – Priyesh Kumar May 23 '17 at 13:15
  • @PriyeshKumar - I didn't say that it was hard, or would create lots of code. I said it was underhand - in the way that if a site does not offer an API, and does not allow Cross Domain Requests - then it's obvious they don't want their service used in that way. – Tom May 23 '17 at 13:17

1 Answers1

-1

You can use a browser plugin that will allow you to request any site with ajax from any source

Chrome example: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi

derplayer
  • 1
  • 3