Skip to content

Commit 2c22351

Browse files
authored
jQuery.get: Add an example using a root-relative path
Added a `jQuery.get()` example to show how to request a different page from the root of the same domain. Closes gh-1152
1 parent 93102d3 commit 2c22351

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

entries/jQuery.get.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,24 @@ $.get( "test.cgi", { name: "John", time: "2pm" } )
116116
]]></code>
117117
</example>
118118
<example>
119-
<desc> Get the test.php page contents, which has been returned in json format (&lt;?php echo json_encode( array( "name"=&gt;"John","time"=&gt;"2pm" ) ); ?&gt;), and add it to the page.</desc>
119+
<desc>Get the test.php page contents, which has been returned in json format (&lt;?php echo json_encode( array( "name"=&gt;"John","time"=&gt;"2pm" ) ); ?&gt;), and add it to the page.</desc>
120120
<code><![CDATA[
121121
$.get( "test.php", function( data ) {
122122
$( "body" )
123123
.append( "Name: " + data.name ) // John
124124
.append( "Time: " + data.time ); // 2pm
125125
}, "json" );
126+
]]></code>
127+
</example>
128+
<example>
129+
<desc>Get another page on the same domain. Outputs to console both the data returned and the type of data returned.</desc>
130+
<code><![CDATA[
131+
// If this was sent on https://api.jquery.com/jQuery.get/ you will
132+
// get the response result of https://api.jquery.com/jQuery.ajax/
133+
$.get( "/jQuery.ajax/", function( data ) {
134+
console.log( typeof data ); // string
135+
console.log( data ); // HTML content of the jQuery.ajax page
136+
});
126137
]]></code>
127138
</example>
128139
<category slug="ajax/shorthand-methods"/>

0 commit comments

Comments
 (0)