views:

87

answers:

2

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?

+2  A: 

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.

jitter
Thanks, jitter! I forgot about this policy. :) Now I can proceed from here :)
Hugo Estrada
A: 

jquery_update

Nikit
And how does that solve the problem? This has nothing to do with "old version of jquery"
jitter
this is not for current problem, just for "Wow... 1.2.6 is old enough to be in a museum. Surprising Drupal don't keep it up to date!"
Nikit