Breaking News
Loading...
, , ,

Why We Forgot to Use These Jquery Functions

Share on Google Plus

While Using Jquery AJAX Functions to post and get the parameters to certain URLs, We always forgot this kind of methods are there in jquery and it will reduce our code structure and size.

jQuery.post()


Description: Load data from the server using a HTTP POST request.




Examples:

Request the test.php page, but ignore the return results.

$.post( "test.php" );
Request the test.php page and send some additional data along (while still ignoring the return results).


$.post( "test.php", { name: "John", time: "2pm" } );
Pass arrays of data to the server (while still ignoring the return results).


$.post( "test.php", { 'choices[]': [ "Jon", "Susan" ] } );

Send form data using Ajax requests


$.post( "test.php", $( "#testform" ).serialize() );
Alert the results from requesting test.php (HTML or XML, depending on what was returned).




$.post( "test.php", function( data ) {
alert( "Data Loaded: " + data );
});

Alert the results from requesting test.php with an additional payload of data (HTML or XML, depending on what was returned).





$.post( "test.php", { name: "John", time: "2pm" })
.done(function( data ) {
alert( "Data Loaded: " + data );
});

jQuery.get()


Description: Load data from the server using a HTTP GET request.



Examples:

Request the test.php page, but ignore the return results.

$.get( "test.php" );

Request the test.php page and send some additional data along (while still ignoring the return results).



$.get( "test.php", { name: "John", time: "2pm" } );
Pass arrays of data to the server (while still ignoring the return results).


$.get( "test.php", { "choices[]": ["Jon", "Susan"] } );
Alert the results from requesting test.php (HTML or XML, depending on what was returned).



$.get( "test.php", function( data ) {
alert( "Data Loaded: " + data );
});
Alert the results from requesting test.cgi with an additional payload of data (HTML or XML, depending on what was returned).




$.get( "test.cgi", { name: "John", time: "2pm" } )
.done(function( data ) {
alert( "Data Loaded: " + data );
});

You Might Also Like

0 comments

About me


Like us on Facebook