javascript - 通过 ajax jquery 调用向服务器发送参数

标签 javascript jquery ajax forms

<分区>

Possible Duplicate:
submitting form and variables together through jquery

我正在使用以下代码通过 ajax、jquery 将表单数据发送到服务器:

// this is the id of the submit button
$("#submitButtonId").click(function() {

    var url = "path/to/your/script.php"; // the script where you handle the form input.

    $.ajax({
           type: "POST",
           url: url,
           data: $("#idForm").serialize(), // serializes the form's elements.
           success: function(data)
           {
               alert(data); // show response from the php script.
           }
         });

    return false; // avoid to execute the actual submit of the form.
});

如果我必须发送我自己的参数/值而不是发布表单数据,我该怎么做? 谢谢。

最佳答案

您可以简单地将表单数据与您自己的数据分开:

data : { 
  myData : 'foo',
  formData : $("#idForm").serialize()
}

关于javascript - 通过 ajax jquery 调用向服务器发送参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13469006/

相关文章:

javascript - 保护 PHP 脚本 - Shopify

javascript - 将键值对象转换为仅值数组

javascript - React 应用程序中的导航

javascript - jQuery - 隐藏元素的最佳方式? (以防止元素在实际隐藏之前闪烁)

jquery - 如何使用 jquery animate 配置滚动速度?

javascript - JSF Javascript 调用 Primefaces 组件

javascript - Axios 400 错误请求调用 then 而不是 catch

javascript - 如何使用 Angularjs 将 JSON 文件从本地计算机加载到变量?

javascript - Grunt Uglify 在 ES6 上失败...

javascript - 将 'type' 属性添加到 dll 加载的脚本标记中