Ajax asynchronous loading fragments of jquery

Source: Internet
Author: User
Tags getscript

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.