jsonp package

jsonp package

   = function the document.onclick () { 
        var URL = "http://127.0.0.1/2019/jsonp/data/jsonp3.php" 
        JSONP (URL, function (RES) { 
            Alert (RES) 
        }, { 
            Pass: "the root " 
            // 5 to save, the callback function name field name received background where 
            // to transfer function parameters own package, placed several revisions packaging good 
            columnName:" CB ", 
            // the 6. the to accept the background field name, transmitting a callback function name, the name of the callback function, no longer valid, they are random line 
            CB: "sdfsdfsdf" 
        }) 
    } 

    function JSONP (URL, Success, Data) { 
        // default parameters 1. processing 
        data = {} || data; 
        // 2. analytical data 
        var str = "";
        for(var i in data){
            str += `${i}=${data[i]}&`;
        }

        // 3. Create a script tag, set the src, ready to open JSONP 
        var script = document.createElement ( "script"); 
        script.src = url + str + "?"; 
        Document.body.appendChild (script); 

        // 4 Defining global function 
      
        window [Data [data.columnName]] = function (RES) { 
            Success (RES); 
        } 

    }

  

Guess you like

Origin www.cnblogs.com/xiaomala/p/11519493.html