The code copy is 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',
// Customize the value of jsonp. If you use jsoncallback, then the server side needs to return an object corresponding to the value of jsoncallback.
jsonp: 'jsoncallback',
//If the parameters to be passed are not passed, you must also write them
data: null,
timeout: 5000,
//Return to Json type
contentType: "application/json;utf-8",
//The object returned by the server segment contains name and openid.
success: function (result) {
document.getElementById('oid').innerText=result.name+":"+result.openid;
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
});
</script>
Server H.ashx
The code copy 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 number is /",/"openid/":/"123456789/"})";
context.Response.Clear();
context.Response.Write(result);
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}