Although jq has jsonp, it has never been successfully used. . So I wrote a simple one myself.
var? jsonp? =? Function? (Website,? Callback)? {
What if? (typeof? url===? Undefined')? {
Throw? That? 1st? param? "Website"? Missing';
}
What if? (typeof? Callback? ===? Undefined')? {
Throw? That? Second? param? "Callback"? Missing';
}
var? jsonpcallback? =? Call back? +? New? Date (). value of();
What if? (typeof? Callback? ! ==? string’)? {
window[jsoncallback]? =? Callback;
Callback? =? jsonpcallback
}? Or what? {
window[jsoncallback]? =? Function? (data)? {
Eval (callback) Call (window,? Data);
}
}
var? Script? =? document . createelement(' script ');
script.setAttribute('type ',? text/JavaScript ');
script.setAttribute('src ',? Website? +? (url.indexOf('?' ))? ==? - 1? '?' ? :? & amp')? +? Callback ='? +? jsonpcallback);
var? Boss? =? document . getelementsbytagname(' head ')[0];
Head.appendChild (script);
}; Then, you call it in the page:
jsonp('/v2/book/ISBN/9787 1 152997 10 ',? Function? (data) (
var? Title? =? Data title;
//? Your own data processing? You can pretend to be. In? Structure to traverse the properties of data.
}); Or add it, so you can get all the returned data (
Function? GetObjectData {
var? F _ this? =? arguments.callee
var? $ul? =? $(' & lt; ul & gt');
for(var? Articles? Are you online? Data) (
var? Row? =? Data [items];
var? $ Li? =? $(' & lt; "Li>");
If (! $.isPlainObject(row)? & amp& amp? ! $.isArray(row)){
$li.append(item? +? ':'? +? Row);
} Otherwise {
$li.append(item)。 append(f _ this(row));
}
$ ul . append($ Li);
}
Return? $ ul
}