{"id":374,"date":"2023-08-25T17:22:35","date_gmt":"2023-08-25T17:22:35","guid":{"rendered":"\/\/api.jquery.com\/?p=374"},"modified":"2025-05-12T16:55:10","modified_gmt":"2025-05-12T16:55:10","slug":"jQuery.get","status":"publish","type":"post","link":"https:\/\/api.jquery.com\/jQuery.get\/","title":{"rendered":"jQuery.get()"},"content":{"rendered":"<article id=\"jQuery-get1\" class=\"entry method\"><h2 class=\"section-title\">\n<span class=\"name\">jQuery.get( url [, data ] [, success ] [, dataType ] )<\/span><span class=\"returns\">Returns: <a href=\"http:\/\/api.jquery.com\/Types\/#jqXHR\">jqXHR<\/a><\/span>\n<\/h2>\n<div class=\"entry-wrapper\">\n<p class=\"desc\"><strong>Description: <\/strong>Load data from the server using a HTTP GET request.<\/p>\n<ul class=\"signatures\">\n<li class=\"signature\">\n<h4 class=\"name\">\n<span class=\"version-details\">version added: <a href=\"\/category\/version\/1.0\/\">1.0<\/a><\/span><a id=\"jQuery-get-url-data-success-dataType\" href=\"#jQuery-get-url-data-success-dataType\"><span class=\"icon-link\"><\/span>jQuery.get( url [, data ] [, success ] [, dataType ] )<\/a>\n<\/h4>\n<ul>\n<li id=\"jQuery-get-url-data-success-dataType-url\">\n<div><strong>url<\/strong><\/div>\n<div>Type: <a href=\"http:\/\/api.jquery.com\/Types\/#String\">String<\/a>\n<\/div>\n<div>A string containing the URL to which the request is sent.<\/div>\n<\/li>\n<li id=\"jQuery-get-url-data-success-dataType-data\">\n<div><strong>data<\/strong><\/div>\n<div>Type: <a href=\"http:\/\/api.jquery.com\/Types\/#PlainObject\">PlainObject<\/a> or <a href=\"http:\/\/api.jquery.com\/Types\/#String\">String<\/a>\n<\/div>\n<div>A plain object or string that is sent to the server with the request.<\/div>\n<\/li>\n<li id=\"jQuery-get-url-data-success-dataType-success\">\n<div><strong>success<\/strong><\/div>\n<div>Type: <a href=\"http:\/\/api.jquery.com\/Types\/#Function\">Function<\/a>( <a href=\"http:\/\/api.jquery.com\/Types\/#PlainObject\">PlainObject<\/a> data, <a href=\"http:\/\/api.jquery.com\/Types\/#String\">String<\/a> textStatus, <a href=\"http:\/\/api.jquery.com\/Types\/#jqXHR\">jqXHR<\/a> jqXHR )<\/div>\n<div>A callback function that is executed if the request succeeds. Required if <code>dataType<\/code> is provided, but you can use <code>null<\/code> or <a href=\"\/jQuery.noop\/\"><code>jQuery.noop<\/code><\/a> as a placeholder. <strong>NOTE:<\/strong> In jQuery 3.x and older, when providing a <code>null<\/code> value for <code>success<\/code> you also have to provide the <code>data<\/code> parameter; you can set it to <code>null<\/code> or <code>undefined<\/code>.<\/div>\n<\/li>\n<li id=\"jQuery-get-url-data-success-dataType-dataType\">\n<div><strong>dataType<\/strong><\/div>\n<div>Type: <a href=\"http:\/\/api.jquery.com\/Types\/#String\">String<\/a>\n<\/div>\n<div>The type of data expected from the server. Default: Intelligent Guess (xml, json, script, text, html).<\/div>\n<\/li>\n<\/ul>\n<\/li>\n<li class=\"signature\">\n<h4 class=\"name\">\n<span class=\"version-details\">version added: <a href=\"\/category\/version\/1.12-and-2.2\/\">1.12-and-2.2<\/a><\/span><a id=\"jQuery-get-settings\" href=\"#jQuery-get-settings\"><span class=\"icon-link\"><\/span>jQuery.get(  [settings ] )<\/a>\n<\/h4>\n<ul><li id=\"jQuery-get-settings-settings\">\n<div><strong>settings<\/strong><\/div>\n<div>Type: <a href=\"http:\/\/api.jquery.com\/Types\/#PlainObject\">PlainObject<\/a>\n<\/div>\n<div>A set of key\/value pairs that configure the Ajax request. All properties except for <code>url<\/code> are optional. A default can be set for any option with <a href=\"\/jQuery.ajaxSetup\/\">$.ajaxSetup()<\/a>. See <a href=\"\/jQuery.ajax\/#jQuery-ajax-settings\">jQuery.ajax( settings )<\/a> for a complete list of all settings. The type option will automatically be set to <code>GET<\/code>.<\/div>\n<\/li><\/ul>\n<\/li>\n<\/ul>\n<div class=\"longdesc\" id=\"entry-longdesc\">\n    <p>This is a shorthand Ajax function, which is equivalent to:<\/p>\n    <div class=\"syntaxhighlighter javascript\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n2\">2<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n3\">3<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n4\">4<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n5\">5<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n6\">6<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code>$.ajax({<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-attr\">url<\/span>: url,<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-attr\">data<\/span>: data,<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-attr\">success<\/span>: success,<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-attr\">dataType<\/span>: dataType<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>});<\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n    <p>The <code>success<\/code> callback function is passed the returned data, which will be an XML root element, text string, JavaScript file, or JSON object, depending on the MIME type of the response. It is also passed the text status of the response. <\/p>\n    <p><strong>As of jQuery 1.5<\/strong>, the <code>success<\/code> callback function is also passed a <a href=\"#jqxhr-object\">\"jqXHR\" object<\/a> (in <strong>jQuery 1.4<\/strong>, it was passed the <code>XMLHttpRequest<\/code> object). However, since JSONP and cross-domain GET requests do not use <abbr title=\"XMLHTTPRequest\">XHR<\/abbr>,  in those cases the <code>jqXHR<\/code> and <code>textStatus<\/code> parameters passed to the success callback are undefined.<\/p>\n    <p>Most implementations will specify a success handler:<\/p>\n    <div class=\"syntaxhighlighter javascript\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n2\">2<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n3\">3<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n4\">4<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code>$.get( <span class=\"hljs-string\">\"ajax\/test.html\"<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"> data <\/span>) <\/span>{<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  $( <span class=\"hljs-string\">\".result\"<\/span> ).html( data );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  alert( <span class=\"hljs-string\">\"Load was performed.\"<\/span> );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>});<\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n    <p>This example fetches the requested HTML snippet and inserts it on the page.<\/p>\n    <h4 id=\"jqxhr-object\">The jqXHR Object<\/h4>\n    <p><strong>As of jQuery 1.5<\/strong>, all of jQuery's Ajax methods return  a superset of the <code>XMLHTTPRequest<\/code> object. This jQuery XHR object, or \"jqXHR,\" returned by <code>$.get()<\/code> implements the Promise interface, giving it all the properties, methods, and behavior of a Promise (see <a href=\"\/category\/deferred-object\/\">Deferred object<\/a> for more information). The <code>jqXHR.done()<\/code> (for success), <code>jqXHR.fail()<\/code> (for error), and <code>jqXHR.always()<\/code> (for completion, whether success or error; added in jQuery 1.6) methods take a function argument that is called when the request terminates. For information about the arguments this function receives, see the <a href=\"\/jQuery.ajax\/#jqXHR\">jqXHR Object<\/a> section of the <code>$.ajax()<\/code> documentation.<\/p>\n    <p>The Promise interface also allows jQuery's Ajax methods, including <code>$.get()<\/code>, to chain multiple <code>.done()<\/code>, <code>.fail()<\/code>, and <code>.always()<\/code> callbacks on a single request, and even to assign these callbacks after the request may have completed. If the request is already complete, the callback is fired immediately.<\/p>\n    <div class=\"syntaxhighlighter javascript\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n2\">2<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n3\">3<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n4\">4<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n5\">5<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n6\">6<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n7\">7<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n8\">8<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n9\">9<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n10\">10<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n11\">11<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n12\">12<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n13\">13<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n14\">14<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n15\">15<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n16\">16<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n17\">17<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n18\">18<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n19\">19<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n20\">20<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n21\">21<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-comment\">\/\/ Assign handlers immediately after making the request,<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-comment\">\/\/ and remember the jqxhr object for this request<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-keyword\">var<\/span> jqxhr = $.get( <span class=\"hljs-string\">\"example.php\"<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  alert( <span class=\"hljs-string\">\"success\"<\/span> );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>})<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  .done(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>    alert( <span class=\"hljs-string\">\"second success\"<\/span> );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  })<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  .fail(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>    alert( <span class=\"hljs-string\">\"error\"<\/span> );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  })<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  .always(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>    alert( <span class=\"hljs-string\">\"finished\"<\/span> );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  });<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code> <\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-comment\">\/\/ Perform other work here ...<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code> <\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-comment\">\/\/ Set another completion function for the request above<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>jqxhr.always(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  alert( <span class=\"hljs-string\">\"second finished\"<\/span> );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>});<\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n    <h4>Deprecation Notice<\/h4>\n    <p>The <code>jqXHR.success()<\/code>, <code>jqXHR.error()<\/code>, and <code>jqXHR.complete()<\/code> callback methods are <strong>removed as of jQuery 3.0<\/strong>. You can use <code>jqXHR.done()<\/code>, <code>jqXHR.fail()<\/code>, and <code>jqXHR.always()<\/code> instead.<\/p>\n  <\/div>\n<h3>Additional Notes:<\/h3>\n<div class=\"longdesc\"><ul>\n<li>\n\t\t\tDue to browser security restrictions, most \"Ajax\" requests are subject to the <a title=\"Same Origin Policy on Wikipedia\" href=\"https:\/\/en.wikipedia.org\/wiki\/Same_origin_policy\">same origin policy<\/a>; the request can not successfully retrieve data from a different domain, subdomain, port, or protocol.\n\t\t<\/li>\n<li>\n\t\t\tIf a request with jQuery.get() returns an error code, it will fail silently unless the script has also called the global <a href=\"\/ajaxError\/\"><code>ajaxError<\/code><\/a> event. Alternatively, as of jQuery 1.5, the <code>.error()<\/code> method of the <code>jqXHR<\/code> object returned by jQuery.get() is also available for error handling.\n\t\t<\/li>\n<li>\n\t\t\tScript and JSONP requests are not subject to the same origin policy restrictions.\n\t\t<\/li>\n<\/ul><\/div>\n<section class=\"entry-examples\" id=\"entry-examples\"><header><h2>Examples:<\/h2><\/header><div class=\"entry-example\" id=\"example-0\">\n<h3>\n\t\t\t\tExample 1<\/h3>\n<p>Request the test.php page, but ignore the return results.<\/p>\n<div class=\"syntaxhighlighter javascript\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code>$.get( <span class=\"hljs-string\">\"test.php\"<\/span> );<\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n<\/div>\n<div class=\"entry-example\" id=\"example-1\">\n<h3>\n\t\t\t\tExample 2<\/h3>\n<p>Request the test.php page and send some additional data along (while still ignoring the return results).<\/p>\n<div class=\"syntaxhighlighter javascript\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code>$.get( <span class=\"hljs-string\">\"test.php\"<\/span>, { <span class=\"hljs-attr\">name<\/span>: <span class=\"hljs-string\">\"John\"<\/span>, <span class=\"hljs-attr\">time<\/span>: <span class=\"hljs-string\">\"2pm\"<\/span> } );<\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n<\/div>\n<div class=\"entry-example\" id=\"example-2\">\n<h3>\n\t\t\t\tExample 3<\/h3>\n<p>Pass arrays of data to the server (while still ignoring the return results).<\/p>\n<div class=\"syntaxhighlighter javascript\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code>$.get( <span class=\"hljs-string\">\"test.php\"<\/span>, { <span class=\"hljs-string\">\"choices[]\"<\/span>: [<span class=\"hljs-string\">\"Jon\"<\/span>, <span class=\"hljs-string\">\"Susan\"<\/span>] } );<\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n<\/div>\n<div class=\"entry-example\" id=\"example-3\">\n<h3>\n\t\t\t\tExample 4<\/h3>\n<p>Alert the results from requesting test.php (HTML or XML, depending on what was returned).<\/p>\n<div class=\"syntaxhighlighter javascript\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n2\">2<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n3\">3<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code>$.get( <span class=\"hljs-string\">\"test.php\"<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"> data <\/span>) <\/span>{<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  alert( <span class=\"hljs-string\">\"Data Loaded: \"<\/span> + data );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>});<\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n<\/div>\n<div class=\"entry-example\" id=\"example-4\">\n<h3>\n\t\t\t\tExample 5<\/h3>\n<p>Alert the results from requesting test.cgi with an additional payload of data (HTML or XML, depending on what was returned).<\/p>\n<div class=\"syntaxhighlighter javascript\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n2\">2<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n3\">3<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n4\">4<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code>$.get( <span class=\"hljs-string\">\"test.cgi\"<\/span>, { <span class=\"hljs-attr\">name<\/span>: <span class=\"hljs-string\">\"John\"<\/span>, <span class=\"hljs-attr\">time<\/span>: <span class=\"hljs-string\">\"2pm\"<\/span> } )<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  .done(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"> data <\/span>) <\/span>{<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>    alert( <span class=\"hljs-string\">\"Data Loaded: \"<\/span> + data );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  });<\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n<\/div>\n<div class=\"entry-example\" id=\"example-5\">\n<h3>\n\t\t\t\tExample 6<\/h3>\n<p>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.<\/p>\n<div class=\"syntaxhighlighter javascript\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n2\">2<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n3\">3<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n4\">4<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n5\">5<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code>$.get( <span class=\"hljs-string\">\"test.php\"<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"> data <\/span>) <\/span>{<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  $( <span class=\"hljs-string\">\"body\"<\/span> )<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>    .append( <span class=\"hljs-string\">\"Name: \"<\/span> + data.name ) <span class=\"hljs-comment\">\/\/ John<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>    .append( <span class=\"hljs-string\">\"Time: \"<\/span> + data.time ); <span class=\"hljs-comment\">\/\/  2pm<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>}, <span class=\"hljs-string\">\"json\"<\/span> );<\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n<\/div>\n<div class=\"entry-example\" id=\"example-6\">\n<h3>\n\t\t\t\tExample 7<\/h3>\n<p>Get another page on the same domain. Outputs to console both the data returned and the type of data returned.<\/p>\n<div class=\"syntaxhighlighter javascript\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n2\">2<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n3\">3<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n4\">4<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n5\">5<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n6\">6<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-comment\">\/\/ If this was sent on https:\/\/api.jquery.com\/jQuery.get\/ you will<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code><span class=\"hljs-comment\">\/\/ get the response result of https:\/\/api.jquery.com\/jQuery.ajax\/<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>$.get( <span class=\"hljs-string\">\"\/jQuery.ajax\/\"<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"> data <\/span>) <\/span>{<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-built_in\">console<\/span>.log( <span class=\"hljs-keyword\">typeof<\/span> data ); <span class=\"hljs-comment\">\/\/ string<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  <span class=\"hljs-built_in\">console<\/span>.log( data ); <span class=\"hljs-comment\">\/\/ HTML content of the jQuery.ajax page<\/span><\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>});<\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n<\/div><\/section>\n<\/div><\/article>","protected":false},"excerpt":{"rendered":"<p>Load data from the server using a HTTP GET request.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,78,101,93],"tags":[],"class_list":["post-374","post","type-post","status-publish","format-standard","hentry","category-shorthand-methods","category-78","category-112-and-22","category-93"],"_links":{"self":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts\/374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/comments?post=374"}],"version-history":[{"count":4,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts\/374\/revisions"}],"predecessor-version":[{"id":1434,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts\/374\/revisions\/1434"}],"wp:attachment":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/media?parent=374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/categories?post=374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/tags?post=374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}