Initiate jsonp request pageCode
<! Doctype html >
< Html >
< Head >
< Meta Charset = "UTF-8" >
< Title > Insert title here </ Title >
< Script SRC = "Http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" > </ Script >
</ Head >
< Body >
< Script >
$. Ajax ({
// Async: false, // use synchronous requests
Type: ' Get ' ,
URL: ' Http: // 127.0.0.1: 8090/outapp/jsonp ' ,
Datatype: ' Jsonp ' , // Select Return Value Type
Jsonp: " Callback " , // Specifies the sending/receiving parameters. The default value is callback.
Timeout: 30000 ,
Error: Function (Jqxhr, textstatus, errorthrown ){
If (Textstatus = " Timeout " ){
Alert ( ' Sorry! Request timeout. Please try again! Or check your network conditions! ' ); Return False ;
} Else If (Textstatus = " Error " | Textstatus = " Parsererror " ){
Alert ( ' Sorry! System error. Please try again! ' ); Return False ;
} Else If (Textstatus = " Abort " ){
Alert ( ' Sorry!ProgramInterrupted. Please try again! ' ); Return False ;
}
},
Success: Function (MSG ){
If ( '' ! = MSG ){
Alert (msg. aa );
} Else {
Alert ( ' The file does not exist! ' );
}
}
});
</ Script >
</ Body >
</ Html >
Code of the Cross-origin request page
$ Callback=$ _ Get['Callback'];
Echo $ Callback. '({"Jsonp": false, "AA": "callbackname "})';
Obviously: the format of page return values required by jsonp is callback (JSON string );
Double quotation marks of JSON strings are recommended to avoid unexpected errors.
The output result of the corresponding final page may be (the callback value has a timestamp and will change): jquery17109581847573505305_1321_5230871 ({"jsonp": false, "AA": "callbackname "})