使用$(form).serializeArray()提交表单,获取不到表单值的问题

  

    最近在做Form表单提交时,使用html标签文本框,表单一直获取不到值,服务器控件就能获取到,最后找到的原因是input的标签没有添加name属性,  具体原因需要查询下ID和Name属性的区别,代码如下:

   $.ajax({
                type: "POST",
                url: "Ajax.aspx",
                data: { opt: 'writelog', rowNum: _rNum, ArrayForm: JSON.stringify(getFormJson($('#fmWriteLog'))) },
                async: false,
                cache: false,
                dataType: 'json',
                success: function (date) {
                    if (date <=0) {
                        alert('保存失败!');
                    }
                    else
                    {
                        alert('保存成功!');
                    }
                }
            });




  

  
工时填写
name="txtDate1" type="text" class="Wdate input" οnfοcus="WdatePicker({isShowClear:true,readOnly:false})" /> name="txtHour1" type="text" οnkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" />


后台代码:

public partial class EMDC_Work_Ajax : System.Web.UI.Page
{
    ManHourBLL manHourBll = new ManHourBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            string opt = Request["opt"] != null ? Request["opt"].Trim() : "";
            if (!string.IsNullOrEmpty(opt))
            {
                HandleOpt(opt);
            }
        }
    }
    /// 
    /// 处理ajax操作
    /// 
    /// 
    /// 
    public void HandleOpt(string opt)
    {
        switch (opt)
        {
            case "writelog"://验证是否允许导入
                {
                    Response.Clear();
                    try
                    {
                        List lst = new List();
                        lst.Clear();
                        string strValue int row = Request.Form["rowNum"]==null?0:MyUnity.ObjToInt32(Request.Form["rowNum"]);
                        string[] array = strValue.Replace("{","").Replace("}","").Replace("\"","").Replace("\"","").Split(',');
                        for (int i = 1; i <= row; i++)
                        {
                            ManHour model = new ManHour();
                            model.uLoginName =array[0].Split(':')[1];
                            model.uRealName = array[1].Split(':')[1];
                            for (int j = 1; j < array.Length; j++)
                            {
                                if(array[j].StartsWith("txtDate" + i))
                                {
                                    model.writeDate = array[j].Split(':')[1];
                                }
                                if (array[j].StartsWith("hdtxtProName" + i))
                                {
                                    model.pCode = MyUnity.ObjToString(array[j].Split(':')[1]);
                                }
                                if (array[j].StartsWith("txtHour" + i))
                                {
                                    model.uHour = MyUnity.ObjToInt32(array[j].Split(':')[1]);
                                }
                            }
                           
                            model.sysDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            lst.Add(model);
                        }
                        Response.Write(InsertLog(lst));
                        Response.End();
                    }
                    catch (Exception ex)
                    {

                        throw ex;
                    }
                    break;
                }
        }
    }
    
    
}



你可能感兴趣的:(Web前端,Web后端)