多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > web前端 > jquery > jQuery dialog 異步調用ashx,webservice數據

jQuery dialog 異步調用ashx,webservice數據

來源:程序員人生   發布時間:2014-05-28 18:48:11 閱讀次數:3136次

jQuery dialog 異步調用ashx,webservice數據

點擊按鈕,在彈出的jQuery.dialog中,顯示異步返回的數據。

WebService可以寫復雜的函數,ashx可以根據傳過來的參數調用不同的方法,達到同樣的效果。

本文用到了博客園TerryFeng的例子。

Html,JS代碼:

代碼
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="test_jQuery_dialog_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>無標題頁</title>
</head>
<body>

<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>

<script src="js/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script>

<script type="text/javascript">
$(
function (){

$('#dialog').dialog({
autoOpen: false,
width: 600,
buttons: {
"Ok": function() {
alert("OK");
$(this).dialog("close");

},
"Cancel": function() {
alert("Cancel");
$(this).dialog("close");

}
}
});

}

)

function show()
{
$('#dialog').dialog('open');
}

function ajax1()
{
$.ajax({
type:"get",
url:"action/test.ashx",
data:{"time":Math.random()},
beforeSend:function(XMLHttpRequest)
{

},
success:function(msg)
{
alert(msg);
}
});
}

function ajax2()
{
$.ajax({
type:"post",
contentType: "application/json",
url:"action/WebService.asmx/HelloWorld",
data:{},
dataType: 'json',
success:function(msg)
{
alert(msg);
}
});
}

function ajax3(setvalue1,setvalue2)
{
if(setvalue1.length==0||setvalue2.length==0)
{
alert('請將兩個文本框輸入完整!');
return false;
}
$.ajax({

type:"post",
contentType: "application/json",
url:"action/WebService.asmx/HelloA",
data:"{a:'"+setvalue1+"',b:'"+setvalue2+"'}",
dataType: 'json',
success:function(msg)
{
alert(msg);
}
});
}

//返回集合
function ajax4()
{
$.ajax({
type: "post",
contentType: "application/json",
url: "action/WebService.asmx/GetArray",
data: "{'i':'10'}",
success: function(msg) {
alert(msg);
}
});
}

//返回復合類型
function ajax5()
{
$.ajax({
type: "post",
contentType: "application/json",
url: "action/WebService.asmx/GetClass",
data: "{}",
success: function(msg) {
$(msg).each(function() {
alert(msg["ID"]+'___'+msg["Value"]);
});

}
});
}

//返回dataset
function ajax6()
{
$.ajax({
type: "post",
url: "action/WebService.asmx/GetDataSet",
data: "{}",
datatype:"xml",
success: function(msg) {

$(msg).find('Table1').each(function() {
alert($(this).find("ID").text()+'___'+$(this).find("Value").text());
});

}
});
}

</script>

<form id="form1" runat="server">
<input id="dialog_link" type="button" value="Show" onclick="show()" />
<div id="dialog" style="display: none; background-color: Aqua; width: 200px; height: 150px;">
WebService參數1<input type="text" id="txtMsg1" /><br/>
WebService參數2<input type="text" id="txtMsg2" /><br/>
<input type="button" value="調用Ashx一般處理程序" onclick="ajax1()" id="btn1" />
<input type="button" value="調用無參數WebService" onclick="ajax2()" id="btn2" />
<input type="button" value="調用有參數WebService" onclick="ajax3(txtMsg1.value,txtMsg2.value)" id="btn3" />
<input type="button" value="調用返回集合的WebService" onclick="ajax4()" id="btn4" />
<input type="button" value="調用返回復合類型的WebService" onclick="ajax5()" id="btn5" />
<input type="button" value="調用返回DataSet的WebService" onclick="ajax6()" id="btn6" />
<div id="dictionary"></div>
In Dialog!
</div>
</form>
</body>
</html>

Ashx代碼:

<%@ WebHandler Language="C#" Class="test" %>

using System;
using System.Web;

public class test : IHttpHandler {

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("Hello A");
context.Response.End();
}

public bool IsReusable {
get {
return false;
}
}

}

WebService:

using System;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Data;

/// <summary>
///WebService 的摘要說明
/// </summary>
[WebService(Namespace = "http://abc.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]

public class WebService : System.Web.Services.WebService
{

public WebService()
{

//如果使用設計的組件,請取消注釋以下行
//InitializeComponent();
}

[WebMethod]
public string HelloWorld()
{
return "Hello C";
}

[WebMethod]
public string HelloA(string a, string b)
{
return "Hello__" + a + "__" + b;
}

[WebMethod]
public List<int> GetArray(int i)
{
List<int> list = new List<int>();

while (i >= 0)
{
list.Add(i--);
}

return list;
}

[WebMethod]
public Class1 GetClass()
{
Class1 cl=new Class1();
cl.ID="qixuejia";
cl.Value="qixuejia.cnblogs.com";
return cl;

}

[WebMethod]
public DataSet GetDataSet()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("ID", Type.GetType("System.String"));
dt.Columns.Add("Value", Type.GetType("System.String"));
DataRow dr = dt.NewRow();
dr["ID"] = "1";
dr["Value"] = "qixuejia.cnblogs.com";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["ID"] = "2";
dr["Value"] = "qixuejia";
dt.Rows.Add(dr);
ds.Tables.Add(dt);
return ds;
}

}
public class Class1
{

private string _ID;
private string _Value;

public string ID
{
get { return _ID; }
set { _ID = value; }
}
public string Value
{
get { return _Value; }
set { _Value = value; }
}
}

出處:http://www.cnblogs.com/qixuejia

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 欧美高清videosfreeⅹ | 免费一级肉体全黄毛片高清 | 性视频一区二区三区免费 | 男女免费观看在线爽爽爽视频 | 最近免费2019中文字幕大全 | 欧美性受xxxx黑人xxxx | 亚洲性色成人 | 最近最新中文字幕大全手机在线 | 亚亚洲乱码一二三四区 | 永久在线观看www免费视频 | 国产亚洲欧美在线播放网站 | 亚洲一区二区三区在线 | 国产精品久久亚洲一区二区 | 国产精品亚洲综合一区 | 在线视频 一区二区 | 成人午夜在线视频 | 久久天天躁狠狠躁夜夜2020一 | 福利视频欧美一区二区三区 | 三级黄在线观看 | 中文字幕之中文字幕 | 精品1州区2区3区4区产品乱码 | 亚洲爽爽 | 性欧美18xx | 久久久精品3d动漫一区二区三区 | 中文在线日本免费永久18近 | 性欧美www| 欧美18videosex性欧美tube1080 | 国产在线伊人 | 日本资源在线 | 精品九九久久国内精品 | 日本在线视频一区二区三区 | 国产亚洲欧美在线播放网站 | 国产成人亚洲精品 | 亚洲情人网 | 国产精品自拍在线 | 精品国产一区二区三区www | 国产精品久久久久久福利漫画 | 高清欧美性猛交xxxx黑人猛交 | 国产精品欧美一区二区三区不卡 | 一区二区在线视频 | 久久久久视频精品网 |