views:

35

answers:

1

I'm trying to get the response text of www.google.com/movies using jQuery.

I have tried from $.load to $.get, $.ajax, etc...

Anybody can tell me if this is possible?

Some of my failed attempts:

$(document).ajaxError(function () { 
  alert('ajax error');
});

$(document).load("http://www.google.com/movies?near=joinville,Santa+Catarina,Brazil", null, function (responseText) {   
  alert("Response:\n" + responseText);
});

$.getJSON("http://www.google.com/movies?near=joinville,Santa+Catarina,Brazil&callback=?",
  function (responseText) {
    if (responseText)
      alert("Response:\n" + responseText);
    else
      alert("fail");
  }
);

$.get("http://www.google.com/movies?near=joinville,Santa+Catarina,Brazil",
  null,
  function (responseText) {
    if (responseText)
      alert("Response:\n" + responseText);
    else
      alert("you fail again");
  }
);

$.ajax({
  cache: false,
  url: "http://www.google.com/movies?near=joinville,Santa+Catarina,Brazil",
  dataType: 'html',
  success: function (responseText) {
    if (responseText)
      alert("Response:\n" + responseText);
    else
      alert("you fail again");
  }
});
+3  A: 

Same old ban on cross-domain requests:
http://en.wikipedia.org/wiki/Same_origin_policy

The most common work-around is to do this query on server side. (I don't think Google has AJAX API for its movie service)

Nikita Rybak
I was afraid of that... but something strange is happening here. Try to run this jQuery using Chrome.$.getJSON("http://www.google.com/movies?near=joinville,Santa+Catarina,Brazil else alert("fail"); });Open up chrome developer tools and you will see an error (small red icon at bottom right). Open that error and you will see the response text that I want (the google html), but obviously it is not a jSON response so an error is thrown when it tries to parse the result. How?
Marcelo de Aguiar
@Marcelo How would google know that you expect page to be returned as JSON or JSONP instead of HTML?
Nikita Rybak