The front page test code is as follows:
<!DOCTYPE HTML><HTML><Head> <styletype= "Text/css">. Gridtable{font-family:Verdana,arial,sans-serif;font-size:11px;Color:#333333;Border-width:1px;Border-color:#666666;Border-collapse:collapse;} </style><Scriptsrc= "Http://code.jquery.com/jquery-1.10.2.min.js"></Script><Script> functionTestajax () {varname= $("#username"). Val (); $.ajax ({type:"Post", URL:"xxxxxxxxxx",//URLs that are properly accesseddata: {name:name}, DataType:"Jsonp", Jsonp:"Jsonpcallback",//Jsonp This property can be used without the specific application of this property to be developedSuccess:function(data) {}}); } functionjsonpcallback (Result)//the method name should be the same as the method name written to response in the background { varcallbackmsg=result.msg; if(callbackmsg== "OK") {alert ("Test success!"); $("#form"). Submit (); } Else{alert (callbackmsg); } } </Script></Head><Body><DivAlign= "Center"><H1>Test</H1><formAction=""ID= "form"> <Tableclass= "Gridtable"> <TR><TD>Name</TD><TD><inputtype= "text"ID= "username" /></TD></TR> <TR><TD><inputtype= "button"value= "CONFIRM"onclick= "Testajax ();"/></TD></TR> </Table></form></Div></Body></HTML>
The appropriate test code for the server side is as follows:
function Test (Request, response) { var name = Request.getparameter ("name"); if (name = = "Test") { Response.Write ("Jsonpcallback ({msg: ' OK '})"); // method name Jsonpcallback, but the method name of the foreground to return the value should be the same name } else { var errmsg = "error Test"; Response.Write ("Jsonpcallback ({msg: '" + errmsg + "'})"); // method name Jsonpcallback, but the method name of the foreground to return the value should be the same name }}
Using jquery's ajax approach for cross-domain access