[英]Send Form Data Through JQuery AJAX / javascript
I have a form like this; 我有这样的表格;
<form action="out.php" method="post">
<input type="hidden" name="a" value="a" />
<input type="hidden" name="b" value="b" />
<input type="hidden" name="c" value="c" />
<input type="hidden" name="d" value="d" />
<input type="hidden" name="e" maxlength="60" value="e" />
<input type="hidden" name="f" value="f" />
<input type="submit" value="Create & Send">
</form>
this form can not be seen by users. 用户看不到此表格。 They just see a submit button like "Create Label & Send To Customer" . 他们只是看到一个提交按钮,例如“创建标签并发送给客户”。 But they need to input Customer's eMail Address. 但是他们需要输入客户的电子邮件地址。 So i have a js code the submit button trigger it. 所以我有一个js代码,提交按钮触发了它。 And it asks the email address. 然后询问电子邮件地址。 The JS code: JS代码:
$('#dialog_prompt').click(function(){
$.prompt("What is customer's email?","",
function(value){
$.msg("So, you like '"+value+"'?");
},
function(){
$.msg("You clicked cancel!");
});
});
So my problem is; 所以我的问题是; when the user submit the button and input the customer's email and hit the ok, JS must send the values from the form & email address to the "out.php". 当用户提交按钮并输入客户的电子邮件并单击确定时,JS必须将表单和电子邮件地址中的值发送到“ out.php”。
So how can I send form data via JS? 那么如何通过JS发送表单数据?
HTML: HTML:
<form action="out.php" method="post">
<input type="hidden" name="em" value="" class="customeremail" />
<input type="hidden" name="a" value="a" />
<input type="hidden" name="b" value="b" />
<input type="hidden" name="c" value="c" />
<input type="hidden" name="d" value="d" />
<input type="hidden" name="e" maxlength="60" value="e" />
<input type="hidden" name="f" value="f" />
<input type="submit" value="Create & Send">
</form>
JS: JS:
$('#dialog_prompt').click(function(){
$.prompt("What is customer's email?","",
function(value){
$('form .customeremail').val(value);
$('form').ajaxSubmit();
},
function(){
$.msg("You clicked cancel!");
});
});
You can send the details using AJAX. 您可以使用AJAX发送详细信息。
$('#dialog_prompt').click(function(){
$.prompt("What is customer's email?","",
function(value){
$.msg("So, you like '"+value+"'?");
$.ajax({
url: "out.php", // url to which details are send
type: 'POST',
data: $('form').serialize(), // pass form details
} ).done (function(data) { // on success
});
},
function(){
$.msg("You clicked cancel!");
});
});
Now you can access the values passed through AJAX in out.php page using $_POST
. 现在,您可以使用$_POST
访问out.php页面中通过AJAX传递的值。
Note : The serialize()
method creates a URL encoded text string by serializing form values. 注意: serialize()
方法通过序列化表单值来创建URL编码的文本字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.