0

I would like to refresh any 60 sec only the values given back from the following code inside a widget, without reload the entire page:

    <?php
    // display Who's Online
    if (class_exists("VisitorMaps")) {
        $visitor_maps = new VisitorMaps();
    }
    if (isset($visitor_maps)) {
       $visitor_maps->visitor_maps_manual_sidebar();
    }
    ?>

Any help will be appreciated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

0

Let me know more about your problem and then i might improve my answer but you can use this js to get a response from server in json format and update only certain elements of html page /* refresh DOM for every key named 'selectors' in data dictionary */

/* both data and data['selectors'] need to be json objects
*/

var getJSON, refreshPage,
  __slice = [].slice;

refreshPage = function() {
  var callback, callbacks, content, data, dom, selector, selectors, _i, _len, _results;

  data = arguments[0], callbacks = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
  selectors = data['selectors'];
  for (selector in selectors) {
    content = selectors[selector];
    if (!(content === '' || content === void 0)) {
      dom = $.toDom(selector);
      setText(dom, content, true);
    }
  }
  _results = [];
  for (_i = 0, _len = callbacks.length; _i < _len; _i++) {
    callback = callbacks[_i];
    if (isFunction(callback)) {
      _results.push(callback(data));
    } else {
      _results.push(callback);
    }
  }
  return _results;
};

/* jquery getJSON function simplified
*/


/* calls the callback function with retrieved data automatically
*/


getJSON = function() {
  var args, callback, data, url;

  url = arguments[0], data = arguments[1], callback = arguments[2], args = 4 <= arguments.length ? __slice.call(arguments, 3) : [];
  return $.getJSON(url, data, function(data, status) {
    if (isFunction(callback)) {
      return callback.apply(null, [data].concat(__slice.call(args)));
    }
  });
};
Arpit Singh
  • 3,387
  • 2
  • 17
  • 11
  • Wich information you need more?. All is there!. Very sample question but very complicate your answer.Sorry, but that doesn't help me!. – Giacinto May 19 '13 at 17:00
  • i know its complicated and u didnt answer me before when i asked if u want to use ajax or not ? and if you know cofeescript ? – Arpit Singh May 19 '13 at 18:40
  • Sorry, I didn't see your question!. I want use that code inside a widget of my Theme Wordpress. So I cannot decide if is better ajax or not, maybe. I try just before some ajax code, but it doesn't work, because I don't know wich file I must load and why. In any case I dont Know coffeescript. – Giacinto May 19 '13 at 19:04
  • I try this ajax, but nothing.
    – Giacinto May 19 '13 at 19:07
  • contavisitatori() is a function in functions.php – Giacinto May 19 '13 at 19:08
  • do you know the id of that widget ? and when you create that widget from php, is the output in html form ? – Arpit Singh May 19 '13 at 19:16
  • The name of plugin is Visitor Maps for wordpress. – Giacinto May 19 '13 at 19:39
  • i dont know that plugin and your solution could be as simple as calling a function "getJSON(url, refreshPage)" every 60 seconds, only if you can trace which url is generating the output you want – Arpit Singh May 19 '13 at 19:42