AJAX Request Using YUI
<html>
<head>
<title>Simple Ajax Request</title>
<script type=”text/javascript” src=”http://yui.yahooapis.com/2.7.0/build/yahoo/yahoo-min.js”></script>
<script type=”text/javascript” src=”http://yui.yahooapis.com/2.7.0/build/event/event-min.js”></script>
<script type=”text/javascript” src=”http://yui.yahooapis.com/2.7.0/build/connection/connection-min.js”></script>
</head>
<body>
<h1>Simple Example of creating Ajax Request</h1>
<script>
//The callback function:
var callback = {
success: function(a){
//Assign the resonse to the HTML element
document.getElementById(‘response’).innerHTML = a.responseText;
},
failure: function(a){
//Alert the failure message
alert(a.statusText);
}
}
//Make the Ajax request:
function ajaxRequest(){
var newRequest = YAHOO.util.Connect.asyncRequest(‘GET’, ‘Request/Url’, callback);
}
</script>
<!–The div element in which the resonse will be shown –>
<div id=”response”></div>
<input type=”button” value=”Create Request” onClick=”ajaxRequest();”>
</body>
</html>
Hope this example helped in better understanding of Ajax using YUI.
Recent Comments