File: index.html

package info (click to toggle)
jqapi 1.7%2Bdfsg-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 3,288 kB
  • sloc: javascript: 632; makefile: 12
file content (117 lines) | stat: -rw-r--r-- 7,736 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang='en'><head><meta http-equiv='content-type' content='text/html; charset=UTF-8' /></head><body>
<div class="entry-content">
        <div class="entry-title roundTop">
          
          <h1 class="jq-clearfix">jQuery.get()</h1>
          <div class="entry-meta jq-clearfix">
                        Categories:
            <span class="category"><a href="http://api.jquery.com/category/ajax/" title="View all posts in Ajax">Ajax</a> &gt; <a href="http://api.jquery.com/category/ajax/shorthand-methods/" title="View all posts in Shorthand Methods">Shorthand Methods</a></span>
  

          </div>

</div>
<div id="jQuery-get1" class="entry method">
<h2 class="jq-clearfix roundTop section-title">
<span class="name">jQuery.get( url [, data]  [, success(data, textStatus, jqXHR)]  [, dataType]  )</span> <span class="returns">Returns: <a class="return" href="http://api.jquery.com/Types/#jqXHR">jqXHR</a></span>
</h2>
<div class="jq-box roundBottom entry-details">
<p class="desc"><strong>Description: </strong>Load data from the server using a HTTP GET request.</p>
<ul class="signatures"><li class="signature" id="jQuery-get-url-data-successdata- textStatus- jqXHR-dataType">
<h4 class="name">
<span class="versionAdded">version added: <a href="/category/version/1.0/">1.0</a></span>jQuery.get( url [, data] [, success(data, textStatus, jqXHR)] [, dataType] )</h4>
<p class="arguement"><strong>url</strong>A string containing the URL to which the request is sent.</p>
<p class="arguement"><strong>data</strong>A map or string that is sent to the server with the request.</p>
<p class="arguement"><strong>success(data, textStatus, jqXHR)</strong>A callback function that is executed if the request succeeds.</p>
<p class="arguement"><strong>dataType</strong>The type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html).</p>
</li></ul>
<div class="longdesc">
<p>This is a shorthand Ajax function, which is equivalent to:</p>
<pre>$.ajax({
  url: <em>url</em>,
  data: <em>data</em>,
  success: <em>success</em>,
  dataType: <em>dataType</em>
});
</pre>
<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>
<p><strong>As of jQuery 1.5</strong>, the <code>success</code> callback function is also passed a <a href="http://api.jquery.com/jQuery.get/#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>(j)XHR</code> and <code>textStatus</code> parameters passed to the success callback are undefined.</p>
<p>Most implementations will specify a success handler:</p>
<pre>$.get('ajax/test.html', function(data) {
  $('.result').html(data);
  alert('Load was performed.');
});
</pre>
<p>This example fetches the requested HTML snippet and inserts it on the page.</p>
<h4 id="jqxhr-object">The jqXHR Object</h4>
<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="http://api.jquery.com/category/deferred-object/">Deferred object</a> for more information). For convenience and consistency with the callback names used by <code><a href="http://api.jquery.com/jQuery.ajax/">$.ajax()</a></code>, it provides <code>.error()</code>, <code>.success()</code>, and <code>.complete()</code> methods. These methods take a function argument that is called when the request terminates, and the function receives the same arguments as the correspondingly-named <code>$.ajax()</code> callback.</p>
<p>The Promise interface in jQuery 1.5 also allows jQuery's Ajax methods, including <code>$.get()</code>, to chain multiple <code>.success()</code>, <code>.complete()</code>, and <code>.error()</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>
<pre>// Assign handlers immediately after making the request,
  // and remember the jqxhr object for this request
  var jqxhr = $.get("example.php", function() {
    alert("success");
  })
  .success(function() { alert("second success"); })
  .error(function() { alert("error"); })
  .complete(function() { alert("complete"); });

  // perform other work here ...

  // Set another completion function for the request above
  jqxhr.complete(function(){ alert("second complete"); });</pre>
</div>
<h3 id="notes-0">Additional Notes:</h3>
<div class="longdesc"><ul>
<li>Due to browser security restrictions, most "Ajax" requests are subject to the <a title="Same Origin Policy on Wikipedia" href="http://en.wikipedia.org/wiki/Same_origin_policy">same origin policy</a>; the request can not successfully retrieve data from a different domain, subdomain, or protocol.</li>
<li>If a request with jQuery.get() returns an error code, it will fail silently unless the script has also called the global <a href="http://api.jquery.com/ajaxError/">.ajaxError() </a> method or. 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.</li>
<li>Script and JSONP requests are not subject to the same origin policy restrictions.</li>
</ul></div>
<h3>Examples:</h3>
<div class="entry-examples" id="entry-examples">
<div id="example-0">
<h4>Example: <span class="desc">Request the test.php page, but ignore the return results.</span>
</h4>
<pre class="prettyprint"><code class="example">$.get("test.php");</code></pre>
</div>
<div id="example-1">
<h4>Example: <span class="desc">Request the test.php page and send some additional data along (while still ignoring the return results).</span>
</h4>
<pre class="prettyprint"><code class="example">$.get("test.php", { name: "John", time: "2pm" } );</code></pre>
</div>
<div id="example-2">
<h4>Example: <span class="desc">pass arrays of data to the server (while still ignoring the return results).</span>
</h4>
<pre class="prettyprint"><code class="example">$.get("test.php", { 'choices[]': ["Jon", "Susan"]} );</code></pre>
</div>
<div id="example-3">
<h4>Example: <span class="desc">Alert out the results from requesting test.php (HTML or XML, depending on what was returned).</span>
</h4>
<pre class="prettyprint"><code class="example">$.get("test.php", function(data){
alert("Data Loaded: " + data);
});</code></pre>
</div>
<div id="example-4">
<h4>Example: <span class="desc">Alert out the results from requesting test.cgi with an additional payload of data (HTML or XML, depending on what was returned).</span>
</h4>
<pre class="prettyprint"><code class="example">$.get("test.cgi", { name: "John", time: "2pm" },
   function(data){
     alert("Data Loaded: " + data);
   });</code></pre>
</div>
<div id="example-5">
<h4>Example: <span class="desc"> Gets 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 adds it to the page.</span>
</h4>
<pre class="prettyprint"><code class="example">$.get("test.php",
   function(data){
     $('body').append( "Name: " + data.name ) // John
              .append( "Time: " + data.time ); //  2pm
   }, "json");</code></pre>
</div>
</div>
</div>
</div>

        </div>

</body></html>