JQuery序列化不起作用

时间:2013-10-08 07:11:56

标签: jquery

我试图在我的表单中序列化数据,但它无效。

manage-user-form是表单的ID。

$('#manage-user-form').live('submit',function(e) {
  e.preventDefault();
  var firstname = $("#firstName").val();
  var lastname = $("#lastName").val();

  // this doesn't work
  alert($(this).serialize())

  // this doesn't work
  var d = $('#manage-user-form').find('input,select,textarea').serialize();
  alert(d);

  // this does work
  alert(firstname);
  alert(lastname);
});

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码:

// Get the form data. This serializes the entire form. pritty easy huh!
var form = new FormData($('#form_step4')[0]);
form.append('view_type','addtemplate');
$.ajax({
    type: "POST",
    url: "savedata.php",
    data: form,
    cache: false,
    contentType: false,
    processData: false,
    success:  function(data){
        //alert("---"+data);
        alert("Settings has been updated successfully.");
        window.location.reload(true);
    }
});

在上述情况下,它会将所有表单数据传输到savedata.php。

相关问题