"You know, the great thing about technology is there's always something new around the corner.
You know, the crappy thing about technology is there's always something new around the corner."
-- anonymous Digg posting, May 2006
So to facilitate experimentation, I've put together this liitle online form. You paste your HTML/Script into it, press the button, and you get back a block of script that you can include as the src property of an "on demand" script tag. This could be returned, as well, by an ASHX handler or ASPX page that accepts items on the querystring, assembles the results as JSON, and returns that plus the script to render it.
function msAddScript( url, query, callback)
eltScript = document.createElement("script");
if( url.indexOf('?') > -1)
url += '&';
url += '?';
url += 'q=' + query +"&callback=" +callback;
The server would return a block of client script that essentially looks like this:
callbackMethod( JSONDataHere );
When a script tag is added to the DOM dynamically as in the above, the script is automatically executed, regardless of what domain it was loaded from! This is why the restrictions on XMLHTTPrequest are, in my opinion, so childish. So the callback is automatically invoked with the JSON data as a parameter and everthing is eval-ed and executed, including whatever DOM contructs you have to build your visible results. I should mention also that Jason Diamond's Anthem.Net has a Manager class that already does all this, including creating JSON representations of every possible object including even a DataSet.
Paste your HTML (including script) code into the following form and press the Convert button and the required changes will be made to your code. It also encloses the code into document.write statements for you.
To show you what can be done with the above, there is an "on demand script tag" in this document that references a source generator for our "Search Related" feature here on eggheadcafe.com. If you highlight any word or short phrase on this page, you can right-click and our "search related": engine script will kick into action and pop up a window full of resuts!