Hide
Search Results

Ajax Request

This example ...

ajax example

Setting Up this Example

  1. Complete the form....

http://www.yap-apps.com/sample/Messengerbuddylist.html

Hosted HTML file

<!doctype html>
<html lang="en-IN">
	<head>
		<style>
		h2{
			color:red;
			font-weight:normal;
		}
		h2 span{
			color:black;
			font-weight:bold;
		}   
		</style>
	</head>
	<body>		
		<h2>
			<span id="result-cell"></span>
		</h2>
		<div>
			<input type='button' id='btst' value='Get SeverTime'/>
		</div>
	</body>
	<script type="text/javascript">
	try {
		function request() {
			// prepare array with key value pair
			var params = [];
			params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
			var random = Math.random(); 			
			var url = "http://yap-apps.com/sample/date.php?format=json&random=" + random;
			gadgets.io.makeRequest(url, response, params);
		};

		function response(obj) {		
			var par = JSON.parse(obj.data);    
			var output = typeof par.Date != 'undefined' ? par.Date : '';
			document.getElementById("result-cell").innerHTML = 'Server time is: '+output;         
		};
		request();//function is called first time to populate server time
		YUE = YAHOO.util.Event;
		YUD = YAHOO.util.Dom;
		YUE.addListener('btst','click',request); //Adding Event listener to get Server time on button click
	}
	catch(e) {
		document.getElementById("result-cell").innerHTML = e.toString() + '<br>Try Again';	
	}
	</script>
</html>

Table of Contents