【问题标题】:Easy jQuery/Ajax question on how to send values from a form关于如何从表单发送值的简单 jQuery/Ajax 问题
【发布时间】:2011-08-01 07:53:55
【问题描述】:

我是 jQuery 和 Ajax 的新手,但我了解一些简单的事情。但是我的问题是我需要在现有代码中添加什么来提交我使用的自动完成脚本的选定值的值?

谢谢。

$("#s").autocomplete("rpc.php", {
    width: 250,
    selectFirst: false,
    minChars: 3,
    scroll:true,
    matchContains: true,
    scrollHeight: 250
}).result(function(event, item) {
     $.ajax({
        // what to send here?

            })
});

<form method="get" action=".php">
<input type="text" name="s" id="s" class="inputsearch">
<input id="searchform" type="submit">
</form>

【问题讨论】:

  • 你为什么不让你的代码更简单呢?分隔代码以提交表单和自动完成。它使您的代码更易于理解和维护。所以你可以使用表单事件'onSubmit'。

标签: javascript jquery ajax


【解决方案1】:
.result(function(event, item) {
 $.ajax(
     {
         data: item,
         url: "insert url here",
     })
 });

【讨论】:

  • 并且很可能还提供success函数,因为我们通常必须在调用成功时做一些事情。
【解决方案2】:

jQuery AJAX form submission not working 展示了一个使用 ajax 提交表单的好例子。您只需将值 'post' 更改为 'get'

【讨论】:

    猜你喜欢
    • 2011-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 2019-09-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多