is it possible to use jQuery %Json function to load a javascriptfile.js asynchronously?
but what should the json response be?
scrippie
2009-11-06 07:26:39
There shouldn't be a JSON response. You asked to load a script, not process a piece of JSON data.
David Dorward
2009-11-06 07:35:51
i need the script.js embeded in the Json response, it gets a different file depending on response.
scrippie
2009-11-06 07:43:40
the js file is part of the response
scrippie
2009-11-06 10:01:03
That sounds decidedly dirty, but generate a script element and a text node containing the data extracted from the JSON. append the text to the script and the script to the body.
David Dorward
2009-11-06 12:34:41
+1
A:
If you're trying to load an external JavaScript file then you should use Ramon's suggestions.
But if you're for sure that the response format is JSON you could use the getJSON which loads JSON data using an HTTP GET request.
jQuery.getJSON( url, [data], [callback] )
SpartanBeg
2009-11-06 08:54:10
A:
Here's pure JavaScript coding that downloads a JavaScript file and put it in the header page itself (if you plan to have a very lightweight page that is instantaneously visible then download JavaScript file in the background) :
var getheadTag = document.getElementsByTagName('head')[0];
setjs = document.createElement('script');
setjs.setAttribute('type', 'text/javascript');
getheadTag.appendChild(setjs);
setjs.text = x.responseText;
Olivier Pons
2009-11-06 09:20:52