Jquery's principles and examples of ajax cross domain requests
- 2020-03-30 02:53:48
- OfStack
Client-side JQuery. Ajax call code example:
$.ajax({
type : "get",
async:false,
url : "http://www.xxx.com/ajax.do",
dataType : "jsonp",
jsonp: "callbackparam",//The server is used to receive the parameter of the function name of the callback call
jsonpCallback:"success_jsonpCallback",//The function name of the callback
success : function(json){
alert(json);
alert(json[0].name);
},
error:function(){
alert('fail');
}
});
Sample code for the server to return data:
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
String callbackFunName = context.Request["callbackparam"];
context.Response.Write(callbackFunName + "([ { name:"John"}])");
}