Code can't run, don't know where is wrong, there is the problem, here where the data come from below, why there are data, let me very confused, can you explain this process of data transmission, in the browser output when there is a problem, ask everybody to help point out thank you!
Js code:
What HTML pages without content, only the introduction of js file and jQuery module
Source:
$. Ready=function () {
//encapsulating the json
Function getJSONP (url, callback) {//json is composed of the callback function and data
if (! Url) {return; }//if the url is empty, do not run
//to generate random function name
Var a=[' a ', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'I' and 'j'].
//to generate random subscript
R1=Math. Floor (Math. The random (10);
R2=Math. Floor (Math. The random (10);
R3=Math. Floor (Math. The random (10);
Var name='getJSONP' + a (r1) + a (r2) + a (r3);
Var cbname='getJSONP.' + name;
The console. The log (cbname);
//determine whether in the url contains a question mark, handling url
If (url. IndexOf ('? ')==1) {
Url +='? The json='+ cbname;
}
The else {
Url +='& amp; The json '+ cbname;
}
//script execution defined callback
GetJSONP [name]=function (data) {
Try {
The callback & amp; & The callback (data);
}
The catch (e) {}
The finally {
//delete the function as well as the script tags, prevent pollution
The delete getJSONP [name].
Script. ParentNode. RemoveChild (script);
}
}
//to dynamically create the script tag
Var script=document. The createElement method (' script ');
//define the SRC
Script SRC=https://bbs.csdn.net/topics/url;
Document. The getElementsByTagName (" head ") [0]. The appendChild (script).
}
GetJSONP (' https://class.imooc.com/api/jsonp ', function (data) {
console.log(data);
});
}
CodePudding user response:
Ah, no one to help have a lookCodePudding user response:
No one??? And?????CodePudding user response:
https://blog.csdn.net/badmoonc/article/details/82289252