復(fù)制代碼 代碼如下:
 
<div></div> 
<script type="text/javascript"> 
//獲取貨號(hào) 
$.ajax({ 
url: "http://192.168.1.191/H.ashx", 
type: "GET", 
dataType: 'jsonp', 
//jsonp的值自定義,如果使用jsoncallback,那么服務(wù)器端,要返回一個(gè)jsoncallback的值對(duì)應(yīng)的對(duì)象. 
jsonp: 'jsoncallback', 
//要傳遞的參數(shù),沒(méi)有傳參時(shí),也一定要寫上 
data: null, 
timeout: 5000, 
//返回Json類型 
contentType: "application/json;utf-8", 
//服務(wù)器段返回的對(duì)象包含name,openid. 
success: function (result) { 
document.getElementById('oid').innerText=result.name+":"+result.openid; 
}, 
error: function (jqXHR, textStatus, errorThrown) { 
alert(textStatus); 
} 
}); 
</script> 
復(fù)制代碼 代碼如下:
 
<%@ WebHandler Language="C#" %> 
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/":/"測(cè)試編號(hào)為/",/"openid/":/"123456789/"})"; 
context.Response.Clear(); 
context.Response.Write(result); 
context.Response.End(); 
} 
public bool IsReusable { 
get { 
return false; 
} 
} 
} 
新聞熱點(diǎn)
疑難解答
圖片精選