最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how do i submit a form using get method in jquery - Stack Overflow

programmeradmin1浏览0评论

I am aware of sending form values using the 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

I am aware of sending form values using the 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

Share Improve this question edited Sep 28, 2010 at 16:43 Daniel Dyson 13.2k6 gold badges44 silver badges73 bronze badges asked Sep 28, 2010 at 16:40 PradyPrady 11.3k41 gold badges127 silver badges177 bronze badges 1
  • I'm not quite sure what your question is here. Is it about making the @ not escaped? Since that's correct behavior: the whole point is that it gets escaped, so that your server-side code can read it correctly, without the request being misinterpreted. Sending the form via AJAX won't change that. – Matchu Commented Sep 28, 2010 at 16:42
Add a comment  | 

2 Answers 2

Reset to default 15

If you want to submit a form using jQuery serialize() and GET method, you can do something like this:

If you use PHP:

Form:

<form action='test.php' method='GET' class='ajaxform'>
   <input type='text' name='email'>
</form>

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:

$_GET['email']

More Detail:

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

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.

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

发布评论

评论列表(0)

  1. 暂无评论