jquery Dynamic load Script $.getscript ();

Source: Internet
Author: User
Tags getscript

jQuery.getScript("/path/to/myscript.js", function(data, status, jqxhr) {    /*         做一些加载完成后需要执行的事情    */});

This getscript method returns a JQXHR, and you can use it as follows:

1234567 jquery.getscript ( "/path/to/myscript.js" )      .done ( function () {           /* Yes, there's no problem here. */             .fail ( function () {          Code class= "JScript Comments" >/*, perform the salvage operation immediately */

The most common place to use jquery.getscript is to delay loading a JS plugin and execute it when the load is complete:

1234 jQuery.getScript("jquery.cookie.js")    .done(function() {        jQuery.cookie("cookie_name", "value", { expires: 7 });});

If you need more advanced features, such as loading multiple scripts, or loading different types of files (text files, images, CSS, etc.), I suggest you use a dedicated JavaScript loading tool. If it is to delay loading a JS plugin, to avoid each page to load, this getscript is perfect.

jquery Dynamic load Script $.getscript ();

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.