Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过ajax jquery调用向服务器发送参数_Javascript_Jquery_Ajax_Forms - Fatal编程技术网

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

Javascript 通过ajax jquery调用向服务器发送参数,javascript,jquery,ajax,forms,Javascript,Jquery,Ajax,Forms,可能重复: 我使用以下代码通过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",

可能重复:

我使用以下代码通过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.
});
如果我必须发送我自己的参数/值,而不是post表单数据,我该怎么做?
谢谢。

您只需将表单数据与您自己的数据分开即可:

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

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

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

有几种方法可以做到

或者向表单中添加一个隐藏字段,其中包含需要发送的名称和值。然后,当表单被序列化时,该字段也将被序列化

另一种方法是在序列化表单数据的末尾添加内容

$("#idForm").serialize() + "&foo=bar"

有几种方法可以做到

或者向表单中添加一个隐藏字段,其中包含需要发送的名称和值。然后,当表单被序列化时,该字段也将被序列化

另一种方法是在序列化表单数据的末尾添加内容

$("#idForm").serialize() + "&foo=bar"

您可以通过附加附加字符串来序列化表单数据来实现这一点。像

$submitButtonId.clickfunction{

var url = "path/to/your/script.php"; // the script where you handle the form input.
var data = $("#idForm").serialize() + "&mystring=" + someId
$.ajax({
       type: "POST",
       url: url,
       data: data, // 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.

})

您可以通过附加附加字符串来序列化表单数据来实现这一点。像

$submitButtonId.clickfunction{

var url = "path/to/your/script.php"; // the script where you handle the form input.
var data = $("#idForm").serialize() + "&mystring=" + someId
$.ajax({
       type: "POST",
       url: url,
       data: data, // 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.
})