- Train of Thoughts - http://trainofthoughts.org/blog -

jQuery Cross-Site AJAX Plugin

Posted By Ralf S. Engelschall On Thursday, April 12, 2007 @ 14:25 In Hacking,JavaScript | 14 Comments

It is well known that with the help of a dynamically generated XHTML <script> DOM element one can achieve a portable cross-site variation of an AJAX-style client-server communication as the <script> is not staying under the “same-origin security policy” which restricts the regular AJAX methods. This allows one to load code from a third-party URL in the background.

For this in JavaScript one generates a <script> DOM element with a type attribute set to text/javascript and a src attribute set to the URL of the third-partly URL. That’s it. Well, more or less. But as a jQuery user I wanted this functionality abstracted with a variation of the already existing (plain AJAX) jQuery.getScript() function, which in turn especially allows me to execute a callback function once the script is loaded. And for cleanup and memory leak prevention reasons I wanted that the dynamically generated <script> DOM node is garbage collected automatically, too.

My result is a small jQuery plugin jquery.xsajax.js which provides just this. Find this jQuery plugin in the File Repository [1] area.


Article printed from Train of Thoughts: http://trainofthoughts.org/blog

URL to article: http://trainofthoughts.org/blog/2007/04/12/jquery-plugin-xsajax/

URLs in this post:

[1] File Repository: http://trainofthoughts.org/repo/dirview?d=jquery

Copyright © Ralf S. Engelschall, All Rights Reserved.