0

这是我的代码,成功后我需要拆分(data.d)并存储在变量中,但它不起作用,知道哪里错了吗?

   $("#ckAddrow").click(function () {
                    var abcStr = null;
                    var taskName = $("#ctl00_ContentPlaceHolder1_txttaskname_").val();
                    var sdate = $("#ctl00_ContentPlaceHolder1_txtsdate_").val();
                    var edate = $("#ctl00_ContentPlaceHolder1_txtedate_").val();
                    var hdfieldid = $("#ctl00_ContentPlaceHolder1_hdid").val();
                    var dataString = 'taskname=' + taskName + '&sdate=' + sdate + '&edate=' + edate + '&hfid=' + hdfieldid;
                    // alert(dataString);
                    $.ajax({
                        type: "POST",
                        url: "AutoComWebservices.asmx/insertTasksRecord",
                        data: "{ 'prefix': '" + dataString + "'}",
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                        cache: false,
                        async: true,
                        success: function (data) {
                            abcStr = data.d;
                            alert(abcStr);
                            BuildTable(data.d);
                            //  var valSplit = abcStr.split('-');
                            // var taskname = valSplit[0];
                            //  var startdate = valSplit[1];
                            //  var enddate = valSplit[2];
                            //   var pf = valSplit[3];
                            //   var myscopeid = valSplit[4];
                            //  alert(taskname + " - - - " + myscopeid);
                            // alert(data.d)
                            //   var getId = myscopeid;
                            //  var abc = "<tr id='" + getId + "' class='edit_tr'><td class='edit_td'><span ID='taskName_''" + getId + "' class='lblclass'>'" + taskName + "'</span><input id='taskName_txt_''" + getId + "' class='editbox' type='text' value='" + taskName + "' /></td><td class='edit_td'><span ID='startDate_''" + getId + "' class='lblclass'>'" + sdate + "'</span><input id='startDate_txt_''" + getId + "'  class='editbox sdatedp' type='text' value='" + sdate + "' /></td><td class='edit_td'><span ID='endDate_''" + getId + "' class='lblclass'>'" + edate + "'</span><input id='endDate_txt_''" + getId + "' class='editbox edatedp' type='text' value='" + edate + "' /></td></tr>";
                            //"<tr id=9 class=\"edit_tr"><td class="edit_td"><span ID="taskName_9" class="lblclass">dummy</span><input id="taskName_txt_9" class="editbox" type="text" value=dummy /></td><td class="edit_td"><span ID="startDate_9" class="lblclass">03/14/2013</span><input id="startDate_txt_9"  class="editbox sdatedp" type="text" value=03/14/2013 /></td><td class="edit_td"><span ID="endDate_9" class="lblclass">03/30/2013</span><input id="endDate_txt_9"  class="editbox edatedp" type="text" value=03/30/2013 /></td></tr>"
                        }
                    });
                });

在进一步alert(abcStr); 显示heloo-03/19/2013-03/20/2013-138-52 我需要拆分('-')并保存在变量中;

我的网络方法代码:

[WebMethod]
  public string[] insertTasksRecord(string prefix)
  {        List<string> d = new List<string>();
    string taskname, startdate, enddate,pf;
    string datastr = prefix;
    string myvalue = "";
    string[] val = datastr.Split('&');

    string[] tname = val[0].Split('=');
    taskname = tname[1];

    string[] sdate = val[1].Split('=');
    startdate = sdate[1];


    string[]  edate= val[2].Split('=');
    enddate = edate[1];

    string[] planid = val[3].Split('=');
    pf = planid[1];

    DateTime mysdate = Convert.ToDateTime(startdate);
    DateTime myedate = Convert.ToDateTime(enddate);
          SqlCommand cmd = new SqlCommand(myQuery, connloc);
            connloc.Open();
            string myscopeid = cmd.ExecuteScalar().ToString();
            connloc.Close();
            d.Add(string.Format("{0}-{1}-{2}-{3}-{4}",taskname, startdate, enddate,pf,myscopeid));

              return d.ToArray();
        }
4

0 回答 0