Most of the development will use JSON to provide the AJAX related updates between the server and the browser and the best example for AJAX is that live scoring updates on the site. If any data is changed by using AJAX is going to store on the web server in the format of JSON, where JavaScript is responsible for getting those JSON files.
json.html
[html]
<html>
<head>
<meta content="text/html; charset=utf-8">
<title>AJAX JSON by Splessons</title>
<script type="application/javascript">
function load()
{
var url = "http://date.jsontest.com/";//use any url that have json data
var request;
if(window.XMLHttpRequest){
request=new XMLHttpRequest();//for Chrome, mozilla etc
}
else if(window.ActiveXObject){
request=new ActiveXObject("Microsoft.XMLHTTP");//for IE only
}
request.onreadystatechange = function(){
if (request.readyState == 4 )
{
var jsonObj = JSON.parse(request.responseText);//JSON.parse() returns JSON object
document.getElementById("date").innerHTML = jsonObj.date;
document.getElementById("time").innerHTML = jsonObj.time;
}
}
request.open("GET", url, true);
request.send();
}
</script>
</head>
<body bgcolor="skyblue">
<center>
<img src="E:\splessons.png"></br></br>
Date Of the day: <span id="date"></span><br/> </br>
Time Of the day: <span id="time"></span><br/> </br>
<button type="button" onclick="load()">Load Information</button>
</center>
</body>
</html>
[/html]
In the above code, the
getElementById()
strategy gives back the component that has the ID characteristic with the predefined esteem. This strategy is a standout among the most widely recognized techniques in the HTML DOM and is utilized practically every time to control.
The
Element.innerHTML
property is used to set and get the HTML sentence structure portraying the descendants. of the components.
ActiveX control
is the part of the application. But It is used only one time when the user wants to take print out of that page. There is a form on that JSP page, in which user fills all details and clicks on "print" button. Now blue tooth & ActiveX control comes into the picture. By clicking on a print button, a blue tooth connection is established between PDA & Bluetooth printer. When a connection is established properly, the desired printout comes from the printer.
Where the developer has written the code to get the current time and date, where the separate code has been written for some browsers such as google and IE. To get effective output one image also added.
An
EventHandler
that is called at whenever point the readyState property changes. The callback is called with the UI string. The XMLHttpRequest.onreadystatechange property will have the event handler to be called when the ready state change event is let go, that is each time the readyState property of the XMLHttpRequest changes. The callback is called from the UI thread.
Output: Now compile the code result will be as follows.
In the above image, when clicking on load information the current details will be updated.