简体   繁体   中英

How to refresh or reload data

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.

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)));
    }
  });
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM