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