Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i submit a form using get method in jquery

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

like image 991
Prady Avatar asked Sep 28 '10 16:09

Prady


People also ask

How can we submit a form using jQuery?

jQuery submit() Forms can be submitted either by clicking on the submit button or by pressing the enter button on the keyboard when that certain form elements have focus. When the submit event occurs, the submit() method attaches a function with it to run. Syntax: $(selector).

What is the syntax of jQuery get () method?

The jQuery get() method sends asynchronous http GET request to the server and retrieves the data. Syntax: $. get(url, [data],[callback]);

Which of the following will you use to submit form input array with jQuery?

jQuery serializeArray() Method You can select one or more form elements (like input and/or text area), or the form element itself.


1 Answers

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/

like image 179
Naveed Avatar answered Sep 25 '22 10:09

Naveed