开发者

jQuery $.get() not working in Drupal 6

开发者 https://www.devze.com 2022-12-25 18:03 出处:网络
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

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("WORK开发者_高级运维ING!!");}, '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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号