Copy codeThe Code is as follows:
<Div id = "oid"> </div>
<Script type = "text/javascript">
// Obtain the token
$. Ajax ({
Url: "http: // 192.168.1.191/H. ashx ",
Type: "GET ",
DataType: 'jsonp ',
// Custom jsonp value. If jsoncallback is used, the server returns an object corresponding to the value of jsoncallback.
Jsonp: 'jsoncallback ',
// Specify the parameter to be passed. If no parameter is required, enter the parameter.
Data: null,
Timeout: 5000,
// Return the Json type
ContentType: "application/json; UTF-8 ",
// The objects returned by the server segment include name and openid.
Success: function (result ){
Document. getElementById ('id'). innerText = result. name + ":" + result. openid;
},
Error: function (jqXHR, textStatus, errorThrown ){
Alert (textStatus );
}
});
</Script>
Server H. ashx
Copy codeThe Code is as follows:
<% @ WebHandler Language = "C #" Class = "H" %>
Using System;
Using System. Web;
Public class H: IHttpHandler {
Public void ProcessRequest (HttpContext context ){
Context. Response. ContentType = "text/plain ";
String result = context. request. queryString ["jsoncallback"] + "({\" name \ ": \" test No.: \ ", \" openid \ ": \" 123456789 \"})";
Context. Response. Clear ();
Context. Response. Write (result );
Context. Response. End ();
}
Public bool IsReusable {
Get {
Return false;
}
}
}