Simple Ajax with YUI!!!

For those of you, who want to get started with YUI and Ajax, this would surely prove helpful.


<html><head>
<title>Lets learn YUI</title>

</head>

<body>
<div id="mydiv">

Add some Text or Images if you want to replace dynamically</div>
<a href="Loading.html" onclick="return YUI();">My first AJAX</a>
<script src="build/yahoo/yahoo-min.js" type="text/javascript"></script>

<script src="build/event/event-min.js" type="text/javascript"></script>

<script src="build/connection/connection-min.js" type="text/javascript"></script>

<script type="text/javascript">

//<![CDATA[

function YUI(){

var loadUrl = "Loading.html";

var callback = {

success: function(o) {

document.getElementById('mydiv').innerHTML =  o.responseText;

},

failure: function(o) {

alert("AJAX doesn't work"); //FAILURE

}

}

var transaction = YAHOO.util.Connect.asyncRequest('GET', loadUrl, callback, null);

return false;

}

//]]>

</script>

</body>

</html>

This is how one can simply make AJAX calls using YUI. The code is simple and self explanatory. If you need any help with this, please drop in comments.

Cheerz
Shri

If you are reading article, you might also be interested in the PHP and Scriptaculous Book I have authored.

The book gives you insights about effects, drag-n-drop, slideshows, applications, auto-completion, in-place editing and more. Complete code snippets and explanations.

CHECK out and BUY the PHP and Script.aculo.us book at Packt official site
mybook

http://www.packtpub.com/php-and-script-aculo-us-web-2-0-application-interface/book

3 comments so far

  1. Juan Felipe on

    Hola estoy realizando mi sitio con las librerias de yahoo YUI, pero no logro enviar parĂ¡metros usando AJAX o JSON, podrĂ­an darme la solucion?, gracias.

  2. HARSh on

    hiii i wanna learn YUI i konw c,c++ and java !! can i learn YUI or i have to learn some other languages also !!

  3. HARSh on

    hiii i wanna learn YUI i konw c,c++ and java !! can i learn YUI or i have to learn some other languages also !!!! reply ASAP


Leave a reply