The main use of the load () method and the Getscript () method, the specific example illustrates:
Loads a well-prepared fragment in an existing HTML file, and a popup that prevents the user from further action before the fragment is loaded.
The first is the existing HTML code, without any content:
<! DOCTYPE html>
Propose a JS file Getdata.js write a function of the most primitive popup box hint for example:function GetData () { alert ("The content of the fragment is from Sina Sports");
Propose a fragment box.htm that hosts the fragment content to be loaded:<div>
Finally write main.js to asynchronously load the getdata.js and box.htm into the existing HTML file.$ (document). Ready (function () { //async-load JS file $.getscript ("Js/getdata.js"). Complete (function () { getData (); }) Asynchronously loads the fragment $ ("body"). Text ("Loading ...") $ ("body"). Load ("box.htm", function (url,status,c) { if (status== " Error ") { $ (this). Text (" Fragment loading Failed ");})
Final effect:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Ajax asynchronous loading fragments of jquery