Javascript 我如何使用jquery中的get方法提交表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3815032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how do i submit a form using get method in jquery
提问by Prady
I am aware of sending form values using the method=get
我知道使用 method=get 发送表单值
<FORM METHOD=get ACTION="test.html">
I have a textbox which captures email. When i submit form using the GET method the @ is converted to %40. I had read somewhere that Jquery could send the data across by serializing. How can it be done? Thanks
我有一个捕获电子邮件的文本框。当我使用 GET 方法提交表单时,@ 被转换为 %40。我在某处读到 Jquery 可以通过序列化来发送数据。怎么做到呢?谢谢
回答by Naveed
If you want to submit a form using jQuery serialize()and GET method, you can do something like this:
如果要使用 jQuery serialize()和 GET 方法提交表单,可以执行以下操作:
If you use PHP:
如果您使用 PHP:
Form:
形式:
<form action='test.php' method='GET' class='ajaxform'>
<input type='text' name='email'>
</form>
jQuery:
jQuery:
jQuery(document).ready(function(){
jQuery('.ajaxform').submit( function() {
$.ajax({
url : $(this).attr('action'),
type : $(this).attr('method'),
data : $(this).serialize(),
success : function( response ) {
alert( response );
}
});
return false;
});
});
In test.phpyou can get email like this:
在test.php 中,您可以收到这样的电子邮件:
$_GET['email']
$_GET['email']
More Detail:
更多详情:
回答by BrunoLM
You can use NAVEED's answer to send all the form. Although if you want to send a single field you can use the second parameter of the get function.
您可以使用 NAVEED 的回答发送所有表格。虽然如果您想发送单个字段,您可以使用get 函数的第二个参数。
jQuery.get( url, [ data ], [ callback(data, textStatus, XMLHttpRequest) ], [ dataType ] )
jQuery.get( url, [ data ], [ callback(data, textStatus, XMLHttpRequest) ], [ dataType ] )