Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Ajax and javascript problem.


Fotiman - 1:38 pm on Sep 13, 2010 (gmt 0)


I'm not sure I totally understand what you're trying to do. Can you clarify a bit how the JavaScript PNG animation works?

Here's how I would expect this to work.
1. You have a page that loads in the browser, which has the JavaScript functions need to animate a PNG
2. You have an AJAX connection that is polling the server for updates
3. You would have a callback handler for the AJAX method that would determine what logic to take.

For example:

function animateHealing() {
// This code animates some images
}
function animateAttacked() {
// This code animates some images
}
function updateFromServer(data) {
switch(data) {
case 'heal':
animateHealing();
break;
case 'attacked':
animateAttacked();
break;
}
// resume polling
setTimeout(requestUpdate, 0);
}
function requestUpdate() {
$.get('serverUpdates.php', {/*Any data for server*/}, updateFromServer);
}

Note, that's really just sort of a pseudo code example. The details of how often to request updates is not covered in this example (you'd probably also want to look into something like long-polling [en.wikipedia.org].


Thread source:: http://www.webmasterworld.com/javascript/4201039.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com