1

I wrote a plugin with custom widgets for the Dashboard. It retrieves information from an XML file, and display the information into the widget. The XML file will be modified a bit every few minutes or so. Right now my plugin works perfectly if the user refreshes the page, it will also grab the new XML file and display the new one, but I would like that the widget refreshes the information without having to reload the page.

I assume JS/JQuery will be needed for this, but I'd just like some advice so I can be in the right direction.

Thanks!

  • Maybe you can load the file via ajax and keep checking to see if the file changed. But who spends 5 minutes staring at the dashboard? – gdaniel Sep 5 '14 at 16:28
  • @gdaniel Thanks for the advice, they won't stare at the dashboard but the dashboard will probably always be open on another tab. – Exn Sep 5 '14 at 16:29
  • That makes sense. – gdaniel Sep 5 '14 at 16:31
0

Doing anything without a "page-load" most definitely requires Javascript because your now venturing into the A-Synchronous (AJAX) territory and JQuery is a great library to use for this stuff.

The most simple and straight forward of which is the $.post(...) method. You could then attach this send and receive AJAX call to either a shim of Javascript that uses window.setinterval() or you could just use JQuery timers. By shim I mean a well written class in Javascript or just a set of functions that are set up to detect browser versions and then use the appropriate object to instantiate. Some older browsers do not like JQuery or certain Javascript functions. If you decide on manual Javascript and XHRObjects and to handle the HTTPRequests yourself I would advise looking into which browsers support what.

Either methods will work however its nice to have something like JQuery already done for you so that you can have completely thought out code set done for cross browser compatibility as well as for going backward in browser version compatibility.

All in all I think it might look like this...

delay(function() {
    $.post("myXMLfile", function(data) {
        $('#xmlContainer').html(data);
    });
}, 4000);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.