Is it possible to use jQuery %Json开发者_开发知识库 function to load a javascriptfile.js asynchronously?
$.getScript("/path/to/script.js")
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] )
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;
精彩评论