Friday 15 February 2008

AJAX YAHOO DOMINO - A beginners Guide 7

Righty Ho!

We have built the AJAX objects
We have built an event that instantiated the AJAX objects and passes the request to the server
We have built a Web Agent that catches, processes the request and returns it to the browser.When When the data comes back it is picked up by the success function code which loads the JS we prepared on the server into the DOM.... what now?

Well lets do something with the data!

Cast your mind back to this bit of code

var mySuccessCode = function(o)
{
ProcessMe = evaluate(o.responseText);
RunMe = evaluate(o.argument.nextFunction);
}


The second line RunMe= is the important bit here, once again we use the JS evaluate function to "run" whatever is in o.argument.nextFunction. Which if you remember we set here

myCallBack.argument.nextFunction="dspCars(o.argument.target);"


The last bit of coding we need is the dspCars() function. As you can see the function is passed o.argument.target which was set to be "fordinfo" back in the getData() function.The code looks like this : -


function dspCars(target)
{
myHTML = "";
myHTML = myHTML+"[table border='0' cellpadding='0' cellspacing='0']";
myHTML = myHTML+"[tbody][tr][td]Model[/td][td]Year[/td][td]Price[/td][/tr]";
for(t=0;t[cardata.length;t++)
{
myhtml=myHTML+"[tr]"
myHTML = myHTML+"[td]"+CarData[t].Model+"[/td]";
myHTML = myHTML+"[td]"+CarData[t].Year+"[/td]";
myHTML = myHTML+"[td]"+CarData[t].Price+"[/td]";
myHTML = myHTML+"[/tr]";
}
myHTML = myHTML+"[/table]";
document.getElementById(target).innerHTML = myHTML;
}


(remember to replace all the [] with <>)
This simple agent build a text string of and HTML table with the contents of the CarData array and then "injects" it into the target element.

and as Elmer Fudd would say ... thats all folks...

No comments:

Disqus for Domi-No-Yes-Maybe