• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

JQuery ajaxSetup Example

July 29, 2014 //  by Krishna Srinivasan//  Leave a Comment

The jQuery ajaxSetup method helps default values to set for future ajax requests. It uses an array of new settings; the default settings can be set globally. It also allows us to define globally shared properties for all the ajax requests within a single page and offers to set up default data objects to be appended to all ajax requests.

  • Introduction to JQuery
  • Finding Duplicate Input Elements Using jQuery

JQuery ajaxSetup Syntax

$.ajaxSetup(options)

Following table describes parameters used by ajaxSetup() method.

Name Description
async It is used to send all request in asynchronously way. Default value is true.
beforeSend Before sending the request, the function gets executed.
complete The function gets executed after the request is finished.
contentType It sets content type for the response object when data has to be sent to the server. The default value is “application/x-www-form-urlencoded”.
data The requested data that has to be sent to the server.
dataFilter It is used to handle the XMLHttpRequest data response.
dataType The type of data that is expected from the server.
error The function to be executed when the request gets fail.
global Boolean value indicates whether to trigger the global ajax event handler for this request. By default the value is true
ifModified It is used to check by the server that the page has been modified or no before responding to the request.
jsonp In jsonp request, the callback functions are override.
password The password is used to response to an Http access authentication request.
processData It is used to convert the defaultly object form into query-string form where the data is already submitted.
success The request is succeed when the callback function gets correctly executed.
timeout It is used to set the timeout for request.
type It is used to define the type of request to be made i.e. GET or POST.
url It is used to send request to the specific URL.
username The username is used to response to an Http access authentication request.
xhr It is used to create XMLHttpRequest object.

JQuery ajaxSetup Example

Create one simple text file, save it as sample.txt and add some content in that file as shown in the below file.

AJAX is not a programming language. It is just a technique for creating better and more interactive web applications.

After creating a text file, write the coding part for the processing of the ajaxSetup() method and save it with .html extension.

<!DOCTYPE html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<meta content="utf-8" http-equiv="encoding"/>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("button").click(function () {
            $.ajaxSetup({url:"sample.txt",
            dataType: "text"
            });
             $.ajax( {
             success: function(result) {
                $("div").html(result);
	        }
	     });
         });
   });
</script>
</head>
<body>
<div><h2>JQuery ajaxSetup Method Example</h2></div>
<button>Click</button>
</body>
</html>
  • The above program demonstrates how to access the text data file by setting url path in the program.
  • $(“button”).click(function(event){ }); line defines click event which occurs when button is clicked.
  • $.ajaxSetup({url:”sample.txt”, dataType: “text”}); line defines ajaxSetup() method helps default values to set for future ajax requests. The url: “sample.txt” specifies an url path of the text file and dataType: “text” specifies the type of data in the form of text.
  • success: function(result) {}; statement specifies function to execute when the request succeeds.
  • $(“div”).html(result); line indicates the html method.

JQuery ajaxSetup Demo

When you run the above example, you would get the following output :

JQuery AjaxSetup ExampleJQuery AjaxSetup Example1

Category: jQueryTag: JQuery Basics

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: «jquery JQuery getJSON Example
Next Post: JQuery getScript Example jquery»

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact