简体   繁体   English

如何在jquery中使用get方法提交表单

[英]how do i submit a form using get method in jquery

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. 当我使用GET方法提交表单时,@转换为%40。 I had read somewhere that Jquery could send the data across by serializing. 我读过某个地方,jQuery可以通过序列化发送数据。 How can it be done? 怎么做到呢? Thanks 谢谢

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.php you can get email like this: test.php中,您可以收到如下电子邮件:

$_GET['email']

More Detail: 更多详情:

http://api.jquery.com/jQuery.ajax/ http://api.jquery.com/jQuery.ajax/

You can use NAVEED's answer to send all the form. 您可以使用NAVEED的答案发送所有表格。 Although if you want to send a single field you can use the second parameter of the get function . 尽管如果要发送单个字段,则可以使用get函数第二个参数

jQuery.get( url, [ data ] , [ callback(data, textStatus, XMLHttpRequest) ], [ dataType ] ) jQuery.get(url, [data] ,[callback(data,textStatus,XMLHttpRequest)],[dataType])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM