0

I am trying to send a form data, converted to JSON, to another page with jQuery, . However, I believe my POST method is not working as I am always getting the error message- which only says "error". Can anyone help me catch the exact error or tinker the code for making it correct?

I have checked that the data is properly getting JSONed (the first alert is showing the correct form data).

$('#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);

        }
    });
});
Jon Clements
  • 138,671
  • 33
  • 247
  • 280
lazylionking
  • 21
  • 1
  • 3

1 Answers1

0

I think there is a problem with your URL. It should be: url: "Webpage/function" you are just using the function part. See this example:

http://weblogs.asp.net/karan/archive/2010/09/12/calling-server-side-method-using-jquery-ajax.aspx

Felipe Gavilán
  • 393
  • 2
  • 10
  • I am using ASP.NET Webpages, i.e. Some_File.cshtml. In my case it is is "Insert.cshtml" and that's it - no functions. – lazylionking Dec 16 '12 at 21:16