2013-07-25 145 views
0

我使用.each類遍歷gridview,並將gridview的rowData逐一提交給ajaxsubmit。將行數據傳遞給jquery函數

一切似乎是工作正常。除了var rowData我不知道如何將它傳遞給ajaxsubmit。我曾嘗試使用「#rowData」,但它不起作用。

$("#submit").click(function() { 
       var record; 
       alert("starting"); 
       $("#<%=GridView3.ClientID%> input[id*='chkEmployee']:checked").each(function() { 
        var rowData = { 
         "privateID": $(this).closest('tr').find('.IDName').text(), 
         "Company": $(this).closest('tr').find('.FName').text(), 
         "Dun": $(this).closest('tr').find('.DName').text() 
        }; 
         $("#rowData").ajaxsubmit(
          "./employeeAdd" 
          , function() { 
           jInfo("data base been sumitted" 
           } 
          ); 
          }); 
        }); 

有誰知道如何將rowData正確傳遞給ajaxsubmit嗎?謝謝

回答

0
$("#submit").click(function() { 
var record; 
alert("starting"); 
$("#<%=GridView3.ClientID%> input[id*='chkEmployee']:checked").each(function() { 
$.ajax({ 
    type: "POST", 
    url: "Post.aspx/savePost", 
    data: "{privateID:'" + $(this).closest('tr').find('.IDName').text() + "',Company:'" + $(this).closest('tr').find('.FName').text() + "',Dun:'" +$(this).closest('tr').find('.DName').text()}", 
    contentType: "application/json", 
    dataType: "json", 
    success: function (data) { 
     if (data == undefined) { 
      alert("Error : 219"); 
     } 
     else { 
      alert(data.d); 
     } 
    }, 
    error: function (data) { 
     if (data == undefined) { 
      alert("Error : 465"); 
     } 
     else { 
      alert("Error : 468 " + data.d); 
     } 
    } 
});     
}); 
}); 
0

你指的是"ajaxSubmit" JQuery插件?這是有用的,當你有一個HTML表單,但在這裏,你已經有發佈數據 - 只需使用JQuery post

$.post("./employeeAdd", rowData, function() { 
    jInfo("submitted"); 
});