Copy Code code as follows:
<div id= "OID" ></div>
<script type= "Text/javascript" >
Get the item number
$.ajax ({
URL: "Http://192.168.1.191/H.ashx",
Type: "Get",
DataType: ' Jsonp ',
Jsonp value customization, if using Jsoncallback, then the server side, to return a jsoncallback value corresponding to the object.
JSONP: ' Jsoncallback ',
The arguments to pass, when no arguments are passed, must also be written
Data:null,
timeout:5000,
Return JSON type
ContentType: "Application/json;utf-8",
The object returned by the server segment contains Name,openid.
Success:function (Result) {
document.getElementById (' oid '). innertext=result.name+ ":" +result.openid;
},
Error:function (JQXHR, Textstatus, Errorthrown) {
alert (textstatus);
}
});
</script>
Service-Side H.ashx
Copy Code code as follows:
<%@ WebHandler language= "C #" class= "H"%>
using System;
using System.Web; The
public class H:ihttphandler {
public void ProcessRequest (HttpContext context) {
context. Response.ContentType = "Text/plain";
String result = Context. request.querystring["Jsoncallback"] + ({\ "name\": \ "test number is \", \ "openid\": \ "123456789\"}) ";
Context. Response.Clear ();
Context. Response.Write (Result);
Context. Response.End ();
}
public bool IsReusable {
Get {
return false;
}
}
}