如何序列化当前表格? [英] How to serialize the current form?

查看:130
本文介绍了如何序列化当前表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery序列化提交按钮的形式.但是,当我使用代码时,它消除了return false的影响,并且页面刷新.当我删除序列化代码时,它很好用!

I am using jQuery to serialize the form of the submit button. But when I use the code, it removes the effect of return false and the page refreshes. And when I remove the serialization code, it works good!

我正在使用这个:

$('input[value=Save]').click(function () {
   $.ajax({
      url: '/ajax_requests/update_info',
      data: $(this).form.serialize(),
      success: function (data) {

      }
   });
   return false;
});

我确定我在使用$(this).form.serialize()时犯了一个错误,但是我找不到,也无法在Internet上搜索它.

I am sure I am making a mistake while using $(this).form.serialize() but I can't figure out and neither can I search it on Internet.

推荐答案

jQuery对象没有form属性,您可以使用.prop('form')获取form,但是由于返回的对象是DOM Element对象,使用serialize()时,应使用jQuery包装它,为什么不呢?

jQuery object doesn't have form property, you could get the form using .prop('form') but as the returned object is a DOM Element object, for using serialize() you should wrap it with jQuery, so why not:

$(this.form).serialize(),

这篇关于如何序列化当前表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆