0

I have an aspx.net page with a large form to add an order.
This page contains a table with many order lines.
Per order line, there are 20 form fields and 5 hidden fields.

There is a print button to print the order, but before that it has to save it first.

My problem is that when I use $("form").serializeArray(), the array is 1 to 1.000.000 times empty.
It doesn't matter which browser I use.

This is making me crazy because lot's of users are calling me to fix this problem a.s.a.p.
I don't know to where to start debugging.

  • Is serializeArray() the problemen?
  • Or maybe the postdata is to large or corrupt?
  • Maybe the WebMethod needs some extra attributes?

Here is my print button

<input type='button' title='Print' onclick='PrintOrder(true)' />
function PrintOrder(autosave) {
  if (autosave) {
    // save my order and call a callback function after it's completed
    AutoSaveForm(function () {
      PrintOrder(false);
    });
  } else {
    // show my pdf page
    window.open('printorder.pdf');
    return;
  }
}

var inAutoSaveForm = false;

// this function is needed to autosave my order
// fn is a callback function when it's successfull done.
function AutoSaveForm(fn) {
  if (!inAutoSaveForm) {
    // serializeArray to post my form by the ajax function
    var fields = $("form").serializeArray();

    // json format
    var myData = {
      'orderId': orderId,
      'fields': fields
    };

    myData = JSON.stringify(myData);

    ShowLoader();

    $.ajax({
      type: "POST",
      url: "/Order.aspx/AutoSave",
      contentType: "application/json; charset=utf-8",
      timeout: (1000 * 60 * 10),
      data: myData,
      dataType: "json",
      success: function () {
        setTimeout(function () {
          fn.call();
        }, 25);
      },
      error: function (x, t, m) {
        alert("Error, please try again later.\n\n" + t);
      },
      complete: function (msg) {
        // .. do nothing yet
      }
    });

    inAutoSaveForm = true;
  } else {
    fn.call();
  }
}

Here is my .NET code to save the order.
Maybe I have to put some attributes to the WebMethod ?

[WebMethod]
public static string VerwerkForm(field[] fields) {
    // do the magic
    return "ok";
}

public class field {
    public string name { get; set; }
    public string value { get; set; }
}
4

0 回答 0