简体   繁体   English

表格未序列化

[英]Form not serializing

I've got a form which is loaded through ajax, and posted using ajax. 我有一个通过ajax加载并使用ajax发布的表单。 When try to send its data, nothing is added to post, here's a short version of code 尝试发送其数据时,没有任何内容要发布,这是一段简短的代码

<form id="userForm">
    <input type="text" name="username" />
    <button type="submit">Send</button>
</form>

Javascript: Javascript:

(function($){
    $.fn.ajaxForm = function() {
        var $form = $(this);
        $form.submit(function(event){
            event.preventDefault();
            $.ajax({
                data: $form.serialize(),
                type: 'post',
            });
        });
    }
})(jQuery);

<script type="text/javascript">
    $("#userForm").ajaxForm();
</script>

Everything works fine, request is sent, but $form.serialize() is empty 一切正常,请求已发送,但$ form.serialize()为空

And i only had to ask..... 我只需要问.....

I've also added disabling of fields to the form after submitting which was the reason for the serialize not working. 提交后,我还在表单中添加了禁用字段的功能,这是序列化无法正常工作的原因。 Removed that and it's now fine, sorry for bothering. 删除它,现在可以了,很抱歉打扰。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM