What is jQuery.ajaxSetup() method in jQuery?


The jQuery.ajaxSetup() method sets global settings for future AJAX requests. Here is the description of all the parameters used by this method-

Let’s say we have the following HTML content in result.html file,

<h1>THIS IS RESULT...</h1>

The following is an example showing the usage of this method. Here we make use of success handler to populate returned HTML:

<html>

   <head>
      <title>The jQuery Example</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
       
      <script>
         $(document).ready(function() {
           
            $("#driver").click(function(event){
               // Do global setting.
               $.ajaxSetup({
                  url: "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:#cc0;">
         STAGE
      </div>
       
      <input type = "button" id = "driver" value = "Load Data" />
       
   </body>
</html>

Live Demo

Updated on: 15-Jun-2020

190 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements