Примеры для jQuery.get()


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

1
$.get( "test.php" );

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

1
$.get( "test.php", { name: "John", time: "2pm" } );

Pass arrays of data to the server (while still ignoring the return results).

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

Alert the results from requesting test.php (HTML or XML, depending on what was returned).

1
2
3
$.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).

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

Get the test.php page contents, which has been returned in json format (<?php echo json_encode( array( "name"=>"John","time"=>"2pm" ) ); ?>), and add it to the page.

1
2
3
4
5
$.get( "test.php", function( data ) {
$( "body" )
.append( "Name: " + data.name ) // John
.append( "Time: " + data.time ); // 2pm
}, "json" );