My blog has moved into Beta!



Please note that my blog has changed addresses! It's all new and improved. Hence this old friend of mine had to be left alone. You can visit me at The Last Word (beta). It's all warmed up for you! :)

« Home

About BloggerattoMicrosoft At It Again!Hack UpgradesMicrosoft PowerShellLightbox!!Organise your life, Google style!Printing Blog Pages, CSS style!Credibility of automationLockdown in Sector 4Expandable Posts Version 2.0  »





This is one of the ways in which you can make an asynchronous call (drool) to a JSON feed. JSON is effectively much easier to use than normal XML or XHTML (for AJAX) because as the name says, its already defined in the form of a Javascript object. That's usually a function since most JSON is called via a callback function. I have been looking into JSON as a possible replacement for XML because it reduces lines of code to a bare minimum. And since I am new, something like that helps tons. I'll just briefly explain the working of the dynamic <script> tag as I understand it.

The code for the <script> tag is this:

function dyn_script(url){
     var script=document.createElement('script'); // pretty self explanatory
     script.src=url; // sets the scripts source to the specified url
     script.type="text/javascript";
   
    document.getElementsByTagName('head')[0].appendChild(script); // appends the tag to the head
}

The url will include the callback function as well. You can specify variables for parameterized calls to variable urls. Every JSON feed has a mechanism to specify a callback function, usually by appending a &callback= followed by the name of the function. Once this is done, all you need to do is define the function as callback_function_name(json). The json argument is very important, as all other objects are children of this main one. To make the call, just call the above dyn_script(url) with event handlers and it'll become asynchronous. This is the probably the easiest and most effective way to make a AJAJ call. This works because we already have the function definition in the code (not given above). The dynamic script tag makes a function with function({ ... data ...}); which contains all the data. This is technically calling the function (function calls are made by naming the function), which is parsed the data.

I have been using this method to make up a hack, which I plan to release the moment I can clear up the CSS. Until then, hope to see you exploit this well.


0 Comments




Leave your comment
You can use some HTML tags, such as <b>, <i>, <a>

Or you can sign in as a different user.







Categories

Latest Updated

Subscriptions


Advertisement


Song Of The Day:




Creative Commons License Widgetize!
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.
Aditya Mukherjee © 2005-06 | Powered by Blogger