JQuery序列化不起作用
我正在尝试序列化表单中的数据,但它不起作用JQuery序列化不起作用,jquery,Jquery,我正在尝试序列化表单中的数据,但它不起作用 管理用户表单是表单的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()) // thi
管理用户表单
是表单的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);
});
请尝试以下工作代码:
// 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。您应该使用.on而不是.live。另一个“不工作”问题?来吧,你可以做得更好。查看此网站上的帮助,了解如何提问。“不工作”不是问题描述。我们应该猜测错误和预期/实际行为吗?我在1.3上,所以在function.SKV上没有
,我能看到序列化数据吗?如果是这样,怎么做?你能告诉我要做什么,这样我才能提供更好的ans?我想做的就是序列化我的表单。这就是itvar form=newformdata($('form#u step4')[0]);正在执行相同的操作,并将其传递给savedata.php,以便进行进一步处理,例如:ajax登录..确定。如果我使用console.log,我不应该看到序列化字符串吗?我看不到我的任何值或键。我看到的是,FormData{append=append()}
。。。这比我从这件事上看到的要多得多