亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

js跨域訪問示例(客戶端/服務(wù)端)

 更新時(shí)間:2014年05月19日 16:05:32   作者:  
有關(guān)跨域訪問的的文章,可以搜到很多,基本上大同小異,下面有個(gè)不錯(cuò)的訪問示例,大家可以參考下
復(fù)制代碼 代碼如下:

<div id="oid"></div>
<script type="text/javascript">
//獲取貨號
$.ajax({

url: "http://192.168.1.191/H.ashx",
type: "GET",
dataType: 'jsonp',
//jsonp的值自定義,如果使用jsoncallback,那么服務(wù)器端,要返回一個(gè)jsoncallback的值對應(yīng)的對象.
jsonp: 'jsoncallback',
//要傳遞的參數(shù),沒有傳參時(shí),也一定要寫上
data: null,
timeout: 5000,
//返回Json類型
contentType: "application/json;utf-8",
//服務(wù)器段返回的對象包含name,openid.
success: function (result) {

document.getElementById('oid').innerText=result.name+":"+result.openid;
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
});

</script>

服務(wù)端 H.ashx
復(fù)制代碼 代碼如下:

<%@ 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\":\"測試編號為\",\"openid\":\"123456789\"})";

context.Response.Clear();
context.Response.Write(result);
context.Response.End();


}

public bool IsReusable {
get {
return false;
}
}

}

相關(guān)文章

最新評論