Home > Web Front-end > JS Tutorial > body text

jquery 使用ajax提交form表单

WBOY
Release: 2016-06-01 09:54:56
Original
955 people have browsed it

我们可以使用jquery的serialize()方法来获取表单的数据,然后使用ajax提交表单。 具体代码如下:

<code><form id="contactForm1" action="/your_url.php" method="post">
    <input type="text" name="category" value="123"><br>
    <input type="text" name="school" value="youschool"><br>
</form>
<script type="text/javascript" src="/Public/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
    var frm = $('#contactForm1');
    frm.submit(function (ev) {
        $.ajax({
            type: frm.attr('method'),
            url: frm.attr('action'),
            data: frm.serialize(),
            success: function (data) {
                alert('ok');
            }
        });

        ev.preventDefault();
    });
</script></code>
Copy after login

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template