js Ajax的几种操作方法
具体网址:http://blog.sina.com.cn/s/blog_bfa00a970101c5ns.html
第一种:
$.ajax({
type: "POST",
url: "VIPManager/VipHandler.ashx",
data: "Method=LogOut",
async: false, //是否异步
success: function (data) {
window.location.href = "VIPManager/Register.aspx";
},
error: function () {
alert("error")
}
});
第二种:
1、返回一个文本
$.post("SubmitOrder.ashx", { SCENERY_NAME: $(".h23").text(), SHOWING_ID: $(".tab1 tr").eq(0).text(), Count: value, Price: price, tICKET_STYLE: TICKET_STYLE, tICKET_COUNT: TICKET_COUNT }, function (data, textStatus) {
if (data == "0") {
alert("预定失败"); return;
}
else if (data == "-1") {
alert("请先登录");
window.location.href = "Login.aspx";
}
else {
alert("预定成功");
window.location.href = "../../payment.aspx?divSite=" + $("#divSite").text() + "&PayOrder=" + data + "&price=" + price + "&PayOrderShowingsid=" + $(".tab1 tr").eq(0).text() + "&TICKET_STYLE=" + TICKET_STYLE + "&tICKET_COUNT=" + TICKET_COUNT + "&PayOrderSeat=" + "";
}
}, "text")
2、返回json
$.post("GetActiveCount.ashx", function (data, textStatus) {
for (var i = 0; i < data.length; i++) {
$("<div class=‘activelist‘><a href=‘jINGDIANMENPIAO.aspx?VId=" + data[i].VId + "‘>" + data[i].AName + "</a>" + "<span class=‘zhekou‘>" + data[i].con + "</span>" + "</div>").appendTo($(".hot"));
}
UpdateColor();
}, "json");
后台:
JavaScriptSerializer se = new JavaScriptSerializer();
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
foreach (DataRow dr in dt.Rows) {
Dictionary<string, object> result = new Dictionary<string, object>();
foreach (DataColumn dc in dt.Columns) {
result.Add(dc.ColumnName, dr[dc].ToString());
}
list.Add(result);
} context.Response.Write(se.Serialize(list));
3、返回xml
返回xml的例子目前没找到,期待各位大神添加,再此谢过!
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。