7*4 2015-03-15 11:33 采纳率: 50%
浏览 13

在野生动物园中使用jQuery post

this is my code on client side:

$("#<%=btnAdd.ClientID%>").click(function () {

            var start = $('.aa').html();
            var end = $('.bb').html();
            var comment = $('.cc').html();

            if (start != "ריק" && end != "ריק") {

                $.post("addnewtimedataforuser.ashx", { start: start, end: end, comment: comment },
                    function (data) {
                        var obj = jQuery.parseJSON(data);
                        alert("הוספה רשומה עם כניסה ב" + obj.start + "ויציאה ב" + obj.end + "");
                    })
            }
            else {
                alert("הוסף תאריכים");
            }

        })

this is my code on ashx:

`public class addnewtimedataforuser : IHttpHandler,` System.Web.SessionState.IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        DateTime Start = Convert.ToDateTime(context.Request.Form["start"]);
        DateTime End = Convert.ToDateTime(context.Request.Form["end"]);
        int userID;
        TimeData timeData = new TimeData();
        string json;
        string comment = context.Request.Form["comment"];
        if (context.Session["user"] != null)
        {
            UserClass user = (UserClass)context.Session["user"];
            userID = user.UD_ID;

            try
            {
                String strConnString = ConfigurationManager.ConnectionStrings["Achi"].ConnectionString;
                System.Data.SqlClient.SqlConnection SQLCon = new System.Data.SqlClient.SqlConnection();
                SqlDataReader myReader = default(SqlDataReader);
                SQLCon = new SqlConnection(strConnString);
                SqlCommand sqlCmd = new SqlCommand("usp_TD_Insert", SQLCon);
                sqlCmd.Parameters.AddWithValue("@UD_ID", userID);
                sqlCmd.Parameters.AddWithValue("@TD_start", Start);
                sqlCmd.Parameters.AddWithValue("@TD_end", End);
                sqlCmd.Parameters.AddWithValue("@TD_comment", comment);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                SQLCon.Open();
                if (SQLCon.State == ConnectionState.Open)
                {
                    myReader = sqlCmd.ExecuteReader();


                    while (myReader.Read())
                    {

                        timeData.Insert(myReader.GetValue<int>("TD_ID"), myReader.GetValue<int>("UD_ID"), myReader.GetValue<DateTime?>("TD_start"), myReader.GetValue<DateTime?>("TD_end"), myReader.GetValue<DateTime>("TD_timestemp"));

                    }

                    myReader.Close();
                    SQLCon.Close();
                }

                json = "{\"result\": \"ok\",\"start\":\"" + timeData.TD_start.ToString() + "\",\"end\":\"" + timeData.TD_end.ToString() + "\"}";




            }
            catch (Exception ex)
            {

                json = "{\"result\": \"error\",\"massege\":\""+ex.Message+"\"}";
            }
            context.Response.ContentType = "text/plain";
            context.Response.Write(json);
        }
    }

Works great in all browsers except Safari In addition, activation through consul working also in safari.

I have try to switch to $.ajax without any change

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号