使用 AJAX 和 jQuery 提交表单 [英] Submit form using AJAX and jQuery

查看:40
本文介绍了使用 AJAX 和 jQuery 提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎应该是 jQuery 内置的东西,不需要多于几行代码,但我找不到简单"的解决方案.比如说,我有一个 HTML 表单:

It seems like this should be something built into jQuery without the need for more than a few lines of code, but I can't find the "simple" solution. Say, I have an HTML form:

<form method="get" action="page.html">
    <input type="hidden" name="field1" value="value1" />
    <input type="hidden" name="field2" value="value2" />
    <select name="status">
         <option value=""></option>
         <option value="good">Good</option>
         <option value="bad">Bad</option>
    </select>
</form>

当有人更改选择字段时,我想使用ajax提交表单以更新数据库.我认为有一些方法可以在不手动创建值/属性的情况下执行以下操作,只需将它们全部发送,例如:

When someone changes the select field, I would like to submit the form using ajax to update the database. I thought there would be some way to do the following without manually creating the values/attributes, just send them all, like:

$("select").change(function(){
    $.get("page.html?" + serializeForm());
});

我错过了什么?

推荐答案

这就是结果.

$("select").change(function(){
    $.get("/page.html?" + $(this).parent("form").find(":input").serialize()); 
});

这篇关于使用 AJAX 和 jQuery 提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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