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>"
                        }
                    });
                });

Onalert(abcStr);heloo-03/19/2013-03/20/2013-138-52 さらに、split('-') して変数に保存する必要があることを示しています。

私のウェブメソッドコード:

[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