views:

70

answers:

3

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

A: 

Take a look at this: jQuery.get()

<div id="result"></div>

$.get('ajax/test.html', function(data) {
  $('#result').html(data);
});

What this function does is get the requested html and inject it into the result div.

Daniel Dyson
+2  A: 

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/

NAVEED
Thanks Naveed.. this is exactly what i wanted :)
Prady
@Prady: Welcome
NAVEED
Except you can't get email with $_GET['email'] in a html page, it would need to have either the .php or .phtml extension (unless you set apache to activate the CGI-SCRIPT engine for .html extentions)
Liam Bailey
@Liam Bailey: Thanks for information.
NAVEED
Liam Bailey: Is there anyway you can capture the form values in html page?
Prady
Afraid not. If you want to start processing forms, you will need to start looking at one of the server side languages (PHP is arguably the easiest to learn)
Liam Bailey
+1  A: 

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 ] )

BrunoLM