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,

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.