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
|
<!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.ajaxSetup()</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> > <a href="http://api.jquery.com/category/ajax/low-level-interface/" title="View all posts in Low-Level Interface">Low-Level Interface</a></span>
</div>
</div>
<div id="jQuery-ajaxSetup1" class="entry method">
<h2 class="jq-clearfix roundTop section-title">
<span class="name">jQuery.ajaxSetup( options )</span> <span class="returns"></span>
</h2>
<div class="jq-box roundBottom entry-details">
<p class="desc"><strong>Description: </strong>Set default values for future Ajax requests.</p>
<ul class="signatures"><li class="signature" id="jQuery-ajaxSetup-options">
<h4 class="name">
<span class="versionAdded">version added: <a href="/category/version/1.1/">1.1</a></span>jQuery.ajaxSetup( options )</h4>
<p class="arguement"><strong>options</strong>A set of key/value pairs that configure the default Ajax request. All options are optional. </p>
</li></ul>
<div class="longdesc">
<p>For details on the settings available for <code>$.ajaxSetup()</code>, see <code><a href="/jQuery.ajax">$.ajax()</a></code>. </p>
<p>All subsequent Ajax calls using any function will use the new settings, unless overridden by the individual calls, until the next invocation of <code>$.ajaxSetup()</code>.</p>
<p>For example, the following sets a default for the <code>url</code> parameter before pinging the server repeatedly:</p>
<pre>$.ajaxSetup({
url: 'ping.php'
});</pre>
<p>Now each time an Ajax request is made, the "ping.php" URL will be used automatically:</p>
<pre>$.ajax({
// url not set here; uses ping.php
data: {'name': 'Dan'}
});</pre>
<blockquote><p>Note: Global callback functions should be set with their respective global Ajax event handler methods—<code><a href="/ajaxStart">.ajaxStart()</a></code>, <code><a href="/ajaxStop">.ajaxStop()</a></code>, <code><a href="/ajaxComplete">.ajaxComplete()</a></code>, <code><a href="/ajaxError">.ajaxError()</a></code>, <code><a href="/ajaxSuccess">.ajaxSuccess()</a></code>, <code><a href="/ajaxSend">.ajaxSend()</a></code>—rather than within the <code>options</code> object for <code>$.ajaxSetup()</code>.</p></blockquote>
</div>
<h3>Example:</h3>
<div class="entry-examples" id="entry-examples"><div id="example-0">
<h4><span class="desc">Sets the defaults for Ajax requests to the url "/xmlhttp/", disables global handlers and uses POST instead of GET. The following Ajax requests then sends some data without having to set anything else.</span></h4>
<pre class="prettyprint"><code class="example">$.ajaxSetup({
url: "/xmlhttp/",
global: false,
type: "POST"
});
$.ajax({ data: myData });</code></pre>
</div></div>
</div>
</div>
</div>
</body></html>
|