2012-12-16 27 views
0

我正嘗試使用jQuery將表單數據轉換爲JSON發送到另一個頁面。但是,我相信我的POST方法不起作用,因爲我總是收到錯誤消息 - 只說「錯誤」。任何人都可以幫我捕捉確切的錯誤或修改代碼,使其正確嗎?使用jQuery發佈表單值ASP.NET網頁錯誤

我已檢查數據是否正確獲取JSON(第一個警報顯示正確的表單數據)。

$('#submit').click(function() { 
    var rows = []; 

    $('#Tinfo tbody tr').each(function() { 

     var tds = $(this).children('td'); /* taking all the td elements of the current tr */ 
     rows.push({ 
      'sl': tds.eq(0).find('input').val(), 
      'tname': tds.eq(1).find('input').val(), 
      'ttype': tds.eq(2).find('select').val(), 
      'tduration': tds.eq(3).find('input').val() 

     }); 
    }); 
    rows = JSON.stringify(rows); 
    alert(rows); 

    /* Using the post function to send data over to the database handler page */ 

    $.ajax({ 
     type: "POST", 
     url: "/Insert", 
     data: rows, 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function (data, status) { 
      alert(status); 
     }, 
     error: function (xhr, textStatus, error) { 
      console.log(xhr.statusText); 
      console.log(textStatus); 
      console.log(error); 

     } 
    }); 
}); 

回答