Hugo Estrada
Hugo Estrada

Reputation: 627

jQuery $.get() not working in Drupal 6

So I am running into this problem. I am trying to use $.get() to interact with a REST application within Drupal 6.16, which uses jQuery 1.2.6

I have a test page on the desktop where I run the following code, and it successfully runs the alert.

  url = 'http://api.twitter.com/1/help/test.xml';
  $.get(url, function(){alert("WORKING!!");}, 'xml');

When I try to run it within Drupal, however, the alert is never reached. For some reason, the function never gets triggered.

Any ideas?

Upvotes: 1

Views: 841

Answers (1)

jitter
jitter

Reputation: 54605

All I have to say to this is:

Same origin policy

In a nutshell, the policy permits scripts running on pages originating from the same site to access each other's methods and properties with no specific restrictions, but prevents access to most methods and properties across pages on different sites.

And that's exactly what you are trying to do. Making a ajax-request to a different domain then where the script is located. Which doesn't work because the same origin policy prohibits cross-domain-requests.

Check if the offer a jsonp api and read the jQuery.ajax() documentation how to use/make jsonp cross-domain-requests. Now obviously the alert is never reached as the call doesn't succeed and jQuery thus doesn't call the success-callback you specified.

Upvotes: 2

Related Questions