The jQuery.ajaxSetup( options ) method sets global settings for future AJAX requests. Here is the simple syntax to use this method: Here is the description of all the parameters used by this method: options: A set of key/value pairs that configure the Ajax request. All options are optional. Here is the list of option which could be used as key/value pairs. Except URL, rest of the parameters are optional: Assuming we have following HTML content in /jquery/result.html file: Following is a simple example a simple showing the usage of this method. Here we make use ofsuccess handler to populate returned HTML: To understand it in better way you can Try it yourself.Description:
Syntax:
$.ajaxSetup( options )
Parameters:
Option Description async A Boolean indicating whether to perform the request asynchronously. The default value is true. beforeSend A callback function that is executed before the request is sent. complete A callback function that executes whenever the request finishes. contentType A string containing a MIME content type to set for the request. The default value is application/x-www-form-urlencoded. data A map or string that is sent to the server with the request. dataFilter A function to be used to handle the raw responsed data of XMLHttpRequest. This is a pre-filtering function to sanitize the response. dataType A string defining the type of data expected back from the server (xml, html, json, or script). error A callback function that is executed if the request fails. global A Boolean indicating whether global AJAX event handlers will be triggered by this request. The default value is true. ifModified A Boolean indicating whether the server should check if the page is modified before responding to the request. jsonp Override the callback function name in a jsonp request. password A password to be used in response to an HTTP access authentication request. processData A Boolean indicating whether to convert the submitted data from an object form into a query-string form. The default value is true. success A callback function that is executed if the request succeeds. timeout Number of milliseconds after which the request will time out in failure timeout Set a local timeout (in milliseconds) for the request. type A string defining the HTTP method to use for the request (GET or POST). The default value is GET. url A string containing the URL to which the request is sent. username A username to be used in response to an HTTP access authentication request. xhr Callback for creating the XMLHttpRequest object. Defaults to the ActiveXObject when available (IE), the XMLHttpRequest otherwise. Example:
<h1>THIS IS RESULT...</h1>
<html>
<head>
<title>the title</title>
<script type="text/javascript"
src="/jquery/jquery-1.3.2.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#driver").click(function(event){
// Do global setting.
$.ajaxSetup({
url: "/jquery/result.html"
});
$.ajax( {
success:function(data) {
$('#stage').html(data);
}
});
});
});
</script>
</head>
<body>
<p>Click on the button to load result.html file:</p>
<div id="stage" style="background-color:blue;">
STAGE
</div>
<input type="button" id="driver" value="Load Data" />
</body>
</html>
생각보다 활용범위가 넓다!!
'내가 자꾸 까먹어서 쓰는 개발 이야기 > jQuery' 카테고리의 다른 글
Selectbox의 onchange에서 confirm으로 취소했을 시 상태 원복하기 (0) | 2013.04.04 |
---|---|
jquery.colorbox 에서 테두리 색상 변경하기 (0) | 2013.02.08 |
PHP에서 jQuery로 JSON 배열 받아 사용하기 (0) | 2012.08.13 |
jQuery의 .post() 또는 .get()에서 콜백함수의 리턴값을 글로벌 변수로 사용하기 (0) | 2011.09.22 |
Select Box 활용 노하우 (0) | 2011.03.10 |
최근댓글