954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need some direction

Hello guys, im a PHP system programmer. My javascript/ajax skills are very limited.
What i need to do is updating a div tag whenever an XML file updates.
And if you cant help me with that i can do with just updating a div tag with PHP script inside every now-andthen.
I just need a direction with link or so, i dont expect a ready-made code.

Regards,
Sorcher

Sorcher
Junior Poster
191 posts since Oct 2010
Reputation Points: 16
Solved Threads: 9
 

Sorcher,

First, you need to use AJAX to fetch the data from the server. Easiest way to do AJAX is to use the jQuery lib, which has AJAX methods built in.

Next you have to decide how to employ AJAX to get updates. There are two possible approaches:

Polling: (simple) Make regular AJAX requests. You will need to use javascript's setInterval() or setTimeout().

Long-polling: (difficult) Make a single AJAX request and arrange for the server to make multiple responses without completing the HTTP response. I have never tried this but understand it to be very difficult (impossible?) under Apache. The experts talk about something called Comet but you would need control of your server to install it - not generally possible with cheap/shared web hosting.

Unless you know what you're doing with long-polling/comet, then use the first approach, polling, with setTimeout(makeRequest, x); in the AJAX success handler to initiate another request to your js makeRequest function in x milliseconds time.

To get you started, try reading the jQuery.ajax() entry in the API. The full range of settings is daunting; you should need url, type, data, cache, dataType, success, error and complete.

If you are prepared to try long-polling, then you will need to use the statusCode option. I'm about to try this myself for the first time in a current project.

Airshow

Airshow
WiFi Lounge Lizard
Moderator
2,682 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: