0

I'm trying to get a value from my data array in the beforeSend function, but when I try to display it in the console all I see is undefined.

I tried printing the $(this) variable which also returns undefined.

$("form").submit(function(){
    var data = {
        "action": $(this).attr("id")
    };
    data = $(this).serialize() + "&" + $.param(data);
    $.ajax({
      type:  $(this).attr("method"),
      dataType: $(this).data("type"),
      url: $(this).attr("action"),
      data: data,
      beforeSend: function(data) {
        console.log(data["action"]);
        console.log($(this).attr("method"));
      }
    });
    return false;
  });

How can I read the values stored in the data array in the beforeSend function

krillgar
  • 12,596
  • 6
  • 50
  • 86

1 Answers1

1

Directly, simply:

this.data .

This is serialize String, and then You can do whatever by string parsing/editing.

For example use:

alert(this.data);

for display serialized string.

Świeżu
  • 176
  • 2
  • 6