码迷,mamicode.com
首页 > Web开发 > 详细

js Ajax的几种操作方法

时间:2014-07-22 23:00:52      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   os   

具体网址: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的例子目前没找到,期待各位大神添加,再此谢过!

js Ajax的几种操作方法,布布扣,bubuko.com

js Ajax的几种操作方法

标签:style   blog   http   java   color   os   

原文地址:http://www.cnblogs.com/xiaocandou/p/3861209.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!