jQuery's load method designs dynamic loading and resolves loaded page js

The jQuery load() method is a simple and powerful ajax method.
load() retrieves data from the server and places the returned data in the selected element.grammar

URL s are required, and consecutive are optional. The callback parameter is the function that the load() method is required to execute after execution.
For example:
//This is what loads the test text read from the txt file into the DIV with id div1
With callback function:

            alert("Loading succeeded");

In the code above:
1. responseTxt: Contains results when the call succeeds
2. statusTxt: Contains call status
3. xhr: Contains the XMLHttpRequest object.

Practical application

     * 1:Left menu click jump function
    url = "/projectName-html"+url;
         * Dynamic loading of js files
         * Solution load js cannot debug
         * Note that the naming rule html has the same name as the js file name
        var script = document.createElement("script");
          script.type = "text/javascript";
          if(typeof(callback) != "undefined"){
            if (script.readyState) {
              script.onreadystatechange = function () {
                if (script.readyState == "loaded" || script.readyState == "complete") {
                  script.onreadystatechange = null;
            } else {
              script.onload = function () {
          script.src = url.replace('.html','.js')+"?version="+sy.version;
//  $.getScript("admin/qrcode/qrcodeList.js?version=20171213");
    /*document.write('<script src="admin/operators/operatorsInfo.js?version=20171213"></script>');*/
    ps:  url: mainContext Page url Full Path
        id: mainContext Of id
        pid:mainContext Superior menu Of id

Tags: JQuery Javascript QRCode

Posted on Fri, 05 Jun 2020 13:13:53 -0400 by dougmcc1