JQUERY - AJAXAJAX is an acronym standing for Asynchronous JavaScript and XML and this technology helps us to load data from the server without a browser page refresh. If you are new with AJAX, I would recommend you go through our Ajax Tutorial before proceeding further. JQuery is a great tool which provides a rich set of AJAX methods to develop next generation web application. Loading Simple Data This is very easy to load any static or dynamic data using JQuery AJAX. JQuery provides load() method to do the job: Syntax Here is the simple syntax for load() method:
[selector].load( URL, [data], [callback] );
Here is the description of all the parameters:
Consider the following HTML file with a small JQuery coding:
<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){ $('#stage').load('/jquery/result.html'); }); }); </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> Here load() initiates an Ajax request to the specified URL /jquery/result.html file. After loading this file, all the content would be populated inside <div> tagged with ID stage. Assuming, our /jquery/result.html file has just one HTML line:
<h1>THIS IS RESULT...</h1>
When you click the given button, then result.html file gets loaded. Click on the button to load result.html file:
STAGE
Getting JSON Data There would be a situation when server would return JSON string against your request. JQuery utility function getJSON() parses the returned JSON string and makes the resulting string available to the callback function as first parameter to take further action. Syntax Here is the simple syntax for getJSON() method:
[selector].getJSON( URL, [data], [callback] );
Here is the description of all the parameters:
Consider the following HTML file with a small JQuery coding:
<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){ $.getJSON('/jquery/result.json', function(jd) { $('#stage').html('<p> Name: ' + jd.name + '</p>'); $('#stage').append('<p>Age : ' + jd.age+ '</p>'); $('#stage').append('<p> Sex: ' + jd.sex+ '</p>'); }); }); }); </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> Here JQuery utility method getJSON() initiates an Ajax request to the specified URL/jquery/result.json file. After loading this file, all the content would be passed to the callback function which finally would be populated inside <div> tagged with ID stage. Assuming, our /jquery/result.json file has following json formatted content:
{
"name": "Zara Ali", "age" : "67", "sex": "female" } When you click the given button, then result.html file gets loaded. Click on the button to load result.html file:
STAGE
Passing Data to the Server Many times you collect input from the user and you pass that input to the server for further processing. JQuery AJAX made it easy enough to pass collected data to the server using data parameter of any available Ajax method. Example This example demonstrates how user can pass input to a web server script which would send the same result back and we would print it:
<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){ var name = $("#name").val(); $("#stage").load('/jquery/result.php', {"name":name} ); }); }); </script> </head> <body> <p>Enter your name and click on the button:</p> <input type="input" id="name" size="40" /><br /> <div id="stage" style="background-color:blue;"> STAGE </div> <input type="button" id="driver" value="Show Result" /> </body> </html> Here is the code written in result.php script:
<?php
if( $_REQUEST["name"] ) { $name = $_REQUEST['name']; echo "Welcome ". $name; } ?> Now you can enter any text in the given input box and then click "Show Result" button to see what you have entered in the input box. Enter your name and click on the button:
STAGE
JQuery AJAX Methods You have seen basic concept of AJAX using JQuery. Following table lists down all important JQuery AJAX methods which you can use based your programming need:
The jQuery.ajax( options ) method loads a remote page using an HTTP request. $.ajax() returns the XMLHttpRequest that it creates. In most cases you won't need that object to manipulate directly, but it is available if you need to abort the request manually. Syntax Here is the simple syntax to use this method:
$.ajax( options )
Parameters Here is the description of all the parameters used by this method:
Assuming we have following HTML content in /jquery/result.html file:
<h1>THIS IS RESULT...</h1>
Following is a simple example showing the usage of this method. Here we make use of success handler to populate returned HTML:
<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){ $.ajax( { url:'/jquery/result.html', 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> This will produce the following result: Click on the button to load result.html file:
STAGE
ajaxSetup( options ) Method The jQuery.ajaxSetup( options ) method sets global settings for future AJAX requests. Syntax Here is the simple syntax to use this method:
$.ajaxSetup( options )
Parameters Here is the description of all the parameters used by this method:
Assuming we have following HTML content in /jquery/result.html file:
<h1>THIS IS RESULT...</h1>
Following is a simple example showing the usage of this method. Here we make use of success handler to populate returned HTML:
<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> This will produce the following result: Click on the button to load result.html file:
STAGE
get( url, [data], [callback], [type] ) Method The jQuery.get( url, [data], [callback], [type] ) method loads data from the server using a GET HTTP request. The method returns XMLHttpRequest object. Syntax Here is the simple syntax to use this method:
$.get( url, [data], [callback], [type] )
Parameters Here is the description of all the parameters used by this method:
Assuming we have following PHP content in /jquery/result.php file:
<?php
if( $_REQUEST["name"] ) { $name = $_REQUEST['name']; echo "Welcome ". $name; } ?> getJSON( url, [data], [callback] ) Method The jQuery.getJSON( url, [data], [callback] ) method loads JSON data from the server using a GET HTTP request. The method returns XMLHttpRequest object. Syntax Here is the simple syntax to use this method:
$.getJSON( url, [data], [callback] )
Parameters Here is the description of all the parameters used by this method:
Assuming we have following JSON content in /jquery/result.json file
{
"name": "Zara Ali", "age" : "67", "sex": "female" } Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#driver").click(function(event){ $.get( "result.php", { name: "Zara" }, function(data) { $('#stage').html(data); } ); }); }); </script> </head> <body> <p>Click on the button to load result.html file −</p> <span id="stage" style="background-color:#cc0;"> STAGE </span> <div><input type="button" id="driver" value="Load Data" /></div> </body> </html> This should produce the following result: Click on the button to load result.html file: Click on the button to load result.html file − STAGEgetScript( url, [callback] ) Method The jQuery.getScript( url, [callback] ) method loads and executes a JavaScript file using an HTTP GET request. The method returns XMLHttpRequest object. Syntax Here is the simple syntax to use this method:
$.getScript( url, [callback] )
Parameters Here is the description of all the parameters used by this method:
Assuming we have following JavaScript content in /jquery/result.js file:
function CheckJS(){
alert("This is JavaScript"); } Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#driver").click(function(event){ $.getScript('result.js', function(jd) { // Call custom function defined in script CheckJS(); }); }); }); </script> </head> <body> <p>Click on the button to load result.js file −</p> <div id="stage" style="background-color:blue;"> STAGE </div> <input type="button" id="driver" value="Load Data" /> </body> </html> This should produce the following result Click on the button to load result.js file −
STAGE
post( url, data, callback, type ) Method The jQuery.post( url, [data], [callback], [type] ) method loads a page from the server using a POST HTTP request. The method returns XMLHttpRequest object. Syntax Here is the simple syntax to use this method:
$.post( url, [data], [callback], [type] )
Parameters Here is the description of all the parameters used by this method:
Assuming we have the following PHP content in /jquery/result.php file:
<?php
if( $_REQUEST["name"] ) { $name = $_REQUEST['name']; echo "Welcome ". $name; } ?> Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#driver").click(function(event){ $.post( "result.php", { name: "Zara" }, 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> This should produce the following result Click on the button to load result.html file:
STAGE
load( url, data, callback ) Method The load( url, data, callback ) method loads data from the server and places the returned HTML into the matched element. Syntax Here is the simple syntax to use this method:
[selector].load( url, [data], [callback] )
Parameters Here is the description of all the parameters used by this method:
Assuming we have the following HTML content in /jquery/result.html file:
<h1>THIS IS RESULT...</h1>
Following is a simple example showing the usage of this method.
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#driver").click(function(event){ $('#stage').load('result.html'); }); }); </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> This should produce the following result Click on the button to load result.html file:
STAGE
serialize( ) Method The serialize( ) method serializes a set of input elements into a string of data. Syntax Here is the simple syntax to use this method:
$.serialize( )
Parameters Here is the description of all the parameters used by this method:
Assuming we have the following PHP content in /jquery/serialize.php file:
<?php
if( $_REQUEST["name"] ) { $name = $_REQUEST['name']; echo "Welcome ". $name; $age = $_REQUEST['age']; echo "<br />Your age : ". $age; $sex = $_REQUEST['sex']; echo "<br />Your gender : ". $sex; } ?> Following is a simple example showing the usage of this method:
</html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#driver").click(function(event){ $.post( "serialize.php", $("#testform").serialize(), function(data) { $('#stage1').html(data); } ); var str = $("#testform").serialize(); $("#stage2").text(str); }); }); </script> </head> <body> <p>Click on the button to load result.html file:</p> <div id="stage1" style="background-color:blue;"> STAGE - 1 </div> <br /> <div id="stage2" style="background-color:blue;"> STAGE - 2 </div> <form id="testform"> <table> <tr> <td><p>Name:</p></td> <td><input type="text" name="name" size="40" /></td> </tr> <tr> <td><p>Age:</p></td> <td><input type="text" name="age" size="40" /></td> </tr> <tr> <td><p>Sex:</p></td> <td> <select name="sex"> <option value="Male" selected>Male</option> <option value="Female" selected>Female</option> </select></td> </tr> <tr> <td colspan="2"> <input type="button" id="driver" value="Load Data" /> </td> </tr> </table> </form> </body> </html> This will produce the following result Click on the button to load result.html file:
STAGE - 1
STAGE - 2
serializeArray( ) Method The serializeArray( ) method serializes all forms and form elements like the .serialize() method but returns a JSON data structure for you to work with. The JSON structure returned is not a string. You must use a plugin or third-party library to "stringify". Syntax Here is the simple syntax to use this method:
$.serializeArray( )
Parameters Here is the description of all the parameters used by this method:
Assuming we have the following PHP content in /jquery/serialize.php file:
<?php
if( $_REQUEST["name"] ) { $name = $_REQUEST['name']; echo "Welcome ". $name; $age = $_REQUEST['age']; echo "<br />Your age : ". $age; $sex = $_REQUEST['sex']; echo "<br />Your gender : ". $sex; } ?> Following is a simple example showing the usage of this method:
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#driver").click(function(event){ $.post( "serialize.php", $("#testform").serializeArray(), function(data) { $('#stage1').html(data); } ); var fields = $("#testform").serializeArray(); $("#stage2").empty(); jQuery.each(fields, function(i, field){ $("#stage2").append(field.value + " "); }); }); }); </script> </head> <body> <p>Click on the button to load result.html file:</p> <div id="stage1" style="background-color:blue;"> STAGE - 1 </div> <br /> <div id="stage2" style="background-color:blue;"> STAGE - 2 </div> <form id="testform"> <table> <tr> <td><p>Name:</p></td> <td><input type="text" name="name" size="40" /></td> </tr> <tr> <td><p>Age:</p></td> <td><input type="text" name="age" size="40" /></td> </tr> <tr> <td><p>Sex:</p></td> <td> <select name="sex"> <option value="Male" selected>Male</option> <option value="Female" selected>Female</option> </select></td> </tr> <tr> <td colspan="2"> <input type="button" id="driver" value="Load Data" /> </td> </tr> </table> </form> </body> </html> This will produce the following result Click on the button to load result.html file:
STAGE - 1
STAGE - 2
JQuery AJAX Events You can call various JQuery methods during the life cycle of AJAX call progress. Based on different events/stages, the following methods are available. You can go through all the AJAX Events.
The ajaxComplete( callback ) method attaches a function to be executed whenever an AJAX request completes. This is an Ajax Event. Syntax Here is the simple syntax to use this method:
$(document).ajaxComplete( )
Parameters Here is the description of all the parameters used by this method:
Assuming we have the following HTML content in /jquery/result.html file
<h1>THIS IS RESULT...</h1>
Following is a simple example showing the usage of this method.
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#driver").click(function(event){ $('#stage1').load('result.html'); }); $(document).ajaxComplete(function(event, request, settings){ $("#stage2").html("<h1>Request Complete.</h1>"); }); }); </script> </head> <body> <p>Click on the button to load result.html file:</p> <div id="stage1" style="background-color:blue;"> STAGE - 1 </div> <div id="stage2" style="background-color:blue;"> STAGE - 2 </div> <input type="button" id="driver" value="Load Data" /> </body> </html> This will produce the following result Click on the button to load result.html file:
STAGE - 1
STAGE - 2
ajaxStart( callback ) Method The ajaxStart( callback ) method attaches a function to be executed whenever an AJAX request begins and there is none already active. This is an Ajax Event. Syntax Here is the simple syntax to use this method:
$(document).ajaxStart( callback )
Parameters Here is the description of all the parameters used by this method:
Assuming we have the following HTML content in /jquery/result.html file:
<h1>THIS IS RESULT...</h1>
Following is a simple example showing the usage of this method.
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { /* Global variable */ var count = 0; $("#driver").click(function(event){ $('#stage1').load('result.html'); }); /* Gets called when request starts */ $(document).ajaxStart(function(){ count++; $("#stage2").html("<h1>Starts, Count :" + count + "</h1>"); }); /* Gets called when request complete */ $(document).ajaxComplete(function(event,request,set){ count++; $("#stage3").html("<h1>Completes,Count:" + count + "</h1>"); }); }); </script> </head> <body> <p>Click on the button to load result.html file:</p> <div id="stage1" style="background-color:blue;"> STAGE - 1 </div> <div id="stage2" style="background-color:blue;"> STAGE - 2 </div> <div id="stage3" style="background-color:blue;"> STAGE - 3 </div> <input type="button" id="driver" value="Load Data" /> </body> </html> This will produce the following result Click on the button to load result.html file:
STAGE - 1
STAGE - 2
STAGE - 3
ajaxError( callback ) Method The ajaxError( callback ) method attaches a function to be executed whenever an AJAX request fails. This is an Ajax Event. Syntax Here is a simple syntax to use this method:
$(document).ajaxError( callback )
Parameters Here is the description of all the parameters used by this method:
Following is a simple example showing the usage of this method.
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#driver").click(function(event){ /* Assume result.text does not exist. */ $('#stage1').load('/jquery/result.text'); }); $(document).ajaxError(function(event, request, settings ){ $("#stage2").html("<h1>Error in loading page.</h1>"); }); }); </script> </head> <body> <p>Click on the button to load result.text file:</p> <div id="stage1" style="background-color:blue;"> STAGE - 1 </div> <div id="stage2" style="background-color:blue;"> STAGE - 2 </div> <input type="button" id="driver" value="Load Data" /> </body> </html> This will produce the following result Click on the button to load result.text file:
STAGE - 1
STAGE - 2
ajaxSend( callback ) Method The ajaxSend( callback ) method attaches a function to be executed whenever an AJAX request is sent. This is an Ajax Event. Syntax Here is the simple syntax to use this method:
$(document).ajaxSend( callback )
Parameters Here is the description of all the parameters used by this method:
Assuming we have following HTML content in /jquery/result.html file:
<h1>THIS IS RESULT...</h1>
Following is a simple example showing the usage of this method.
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { /* Global variable */ var count = 0; $("#driver").click(function(event){ $('#stage0').load('result.html'); }); /* Gets called when request starts */ $(document).ajaxStart(function(){ count++; $("#stage1").html("<h1>Starts, Count :" + count + "</h1>"); }); /* Gets called when request is sent */ $(document).ajaxSend(function(evt, req, set){ count++; $("#stage2").html("<h1>Sends, Count :" + count + "</h1>"); $("#stage2").append("<h1>URL :" + set.url + "</h1>"); }); /* Gets called when request complete */ $(document).ajaxComplete(function(event,request,settings){ count++; $("#stage3").html("<h1>Completes, Count :" + count + "</h1>"); }); }); </script> </head> <body> <p>Click on the button to load result.html file:</p> <div id="stage0" style="background-color:blue;"> STAGE - 0 </div> <div id="stage1" style="background-color:blue;"> STAGE - 1 </div> <div id="stage2" style="background-color:blue;"> STAGE - 2 </div> <div id="stage3" style="background-color:blue;"> STAGE - 3 </div> <input type="button" id="driver" value="Load Data" /> </body> </html> This will produce the following result: Click on the button to load result.html file:
STAGE - 0
STAGE - 1
STAGE - 2
STAGE - 3
ajaxStop( callback ) Method The ajaxStop( callback ) method attaches a function to be executed whenever all AJAX requests have ended. This is an Ajax Event. Syntax Here is the simple syntax to use this method:
$[selector].ajaxStop( callback )
Parameters Here is the description of all the parameters used by this method:
Assuming we have following HTML content in /jquery/result.html file:
<h1>THIS IS RESULT...</h1>
Following is a simple example showing the usage of this method.
<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() { /* Global variable */ var count = 0; $("#driver").click(function(event){ $('#stage0').load('/jquery/result.html'); }); /* Gets called when request starts */ $("#stage1").ajaxStart(function(){ count++; $(this).html("<h1>Starts, Count :" + count + "</h1>"); }); /* Gets called when request is sent */ $("#stage2").ajaxSend(function(evt, req, set){ count++; $(this).html("<h1>Sends, Count :" + count + "</h1>"); $(this).append("<h1>URL :" + set.url + "</h1>"); }); /* Gets called when request complete */ $("#stage3").ajaxComplete(function(event,request,settings){ count++; $(this).html("<h1>Completes, Count :" + count + "</h1>"); }); /* Gets called when all requests are ended */ $("#stage4").ajaxStop(function(event,request,settings){ count++; $(this).html("<h1>Stops, Count :" + count + "</h1>"); }); }); </script> </head> <body> <p>Click on the button to load result.html file:</p> <div id="stage0" style="background-color:blue;"> STAGE - 0 </div> <div id="stage1" style="background-color:blue;"> STAGE - 1 </div> <div id="stage2" style="background-color:blue;"> STAGE - 2 </div> <div id="stage3" style="background-color:blue;"> STAGE - 3 </div> <div id="stage4" style="background-color:blue;"> STAGE - 4 </div> <input type="button" id="driver" value="Load Data" /> </body> </html> ajaxSuccess( callback ) Method The ajaxSuccess( callback ) method attaches a function to be executed whenever an AJAX request completes successfully. This is an Ajax Event. Syntax Here is the simple syntax to use this method:
$(document).ajaxSuccess( callback )
Parameters Here is the description of all the parameters used by this method:
Assuming we have the following HTML content in /jquery/result.html file:
<h1>THIS IS RESULT...</h1>
Following is a simple example showing the usage of this method.
<html>
<head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { /* Global variable */ var count = 0; $("#driver").click(function(event){ $('#stage0').load('result.html'); }); /* Gets called when request starts */ $(document).ajaxStart(function(){ count++; $("#stage1").html("<h1>Starts, Count :" + count + "</h1>"); }); /* Gets called when request is sent */ $(document).ajaxSend(function(evt, req, set){ count++; $("#stage2").html("<h1>Sends, Count :" + count + "</h1>"); $("#stage2").append("<h1>URL :" + set.url + "</h1>"); }); /* Gets called when request completes */ $(document).ajaxComplete(function(event,request,settings){ count++; $("#stage3").html("<h1>Completes,Count:" + count + "</h1>"); }); /* Gets called when request is stopped */ $(document).ajaxStop(function(event,request,settings){ count++; $("#stage4").html("<h1>Stops, Count :" + count + "</h1>"); }); /* Gets called when all request completes successfully */ $(document).ajaxSuccess(function(event,request,settings){ count++; $("#stage5").html("<h1>Success,Count :" + count + "</h1>"); }); }); </script> </head> <body> <p>Click on the button to load result.html file:</p> <div id="stage0" style="background-color:blue;"> STAGE - 0 </div> <div id="stage1" style="background-color:blue;">< STAGE - 1 </div> <div id="stage2" style="background-color:blue;"> STAGE - 2 </div> <div id="stage3" style="background-color:blue;"> STAGE - 3 </div> <div id="stage4" style="background-color:blue;"> STAGE - 4 </div> <div id="stage5" style="background-color:blue;"> STAGE - 5 </div> <input type="button" id="driver" value="Load Data" /> </body> </html> This will produce the following result Click on the button to load result.html file:
STAGE - 0
STAGE - 1
STAGE - 2
STAGE - 3
STAGE - 4
STAGE - 5
|