在safari中使用jQuery帖子

时间:2015-03-15 11:33:26

标签: jquery asp.net ajax safari ashx

这是我在客户端的代码:

$("#<%=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("הוסף תאריכים");
            }

        })

这是关于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);
        }
    }

在除Safari之外的所有浏览器中都很棒 此外,通过领事的激活也在野生动物园工作。

我已尝试切换到$ .ajax而不做任何更改

0 个答案:

没有答案