0

I thought I was doing this right but I'm getting the following error in Chrome's JavaScript console:

XMLHttpRequest cannot load https://www.google.com/ig/calculator?hl=en&q=1USD=?JPY. 
Origin  is not allowed by Access-Control-Allow-Origin. 

Any way I try and load the result through JQuery throws this error.

$.ajax({
    type: 'GET',
    url: 'https://www.google.com/ig/calculator?hl=en&q=1USD=?JPY',
    crossDomain: true
})
.fail(function() { alert('error'); })
.success(function(data) { alert(data); })
;
$.get('https://www.google.com/ig/calculator?hl=en&q=1USD=?JPY', function(data) {
    alert(data);
});
$("#test").load('https://www.google.com/ig/calculator?hl=en&q=1USD=?JPY', function(data) {
    alert(data);
});

Even specifying crossDomain to true the AJAX call still fails.

Any idea why or is there a better way to retrieve the results?

Thanks.

7
  • 3
    Because it would appear Google does not allow it. Commented Sep 13, 2013 at 13:06
  • 1
    possible duplicate of JQuery ajax cross domain Commented Sep 13, 2013 at 13:07
  • @epascarello : Google does allow it. Commented Sep 13, 2013 at 13:15
  • 2
    @Tom Why do you think Google allows it? Is it in some documentation somewhere? I'm looking at the HTTP response headers, and it looks pretty clear that Google does not allow it, because they don't send back an Access-Control-Allow-Origin response header, which is the mechanism by which Google allows cross-origin access to their pages. Commented Sep 13, 2013 at 13:30
  • 1
    +1 the downvote seems harsh when the question is complete with code and is a common issue Commented Sep 13, 2013 at 14:11

1 Answer 1

1

Your best bet is to create a REST/JSON service on your own web server that simply returns the remote results from Google's API.

That way any cross-domain problems are avoided and you have more control over future changes to the API (you can for example reformat the content to suit your own nefarious uses:)).

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, the page is in ASP. Will have to try something there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.