开发者

Auto reload a piece of code in PHP using Ajax maybe?

Hello I need the value of nextid to be reloaded without refreshing the whole page. How can I do this? Thanks!

global $wpdb;
$query = "SELECT MAX(ID) FROM $wpdb->posts";
$currid = $wpdb->get_var($query);
$nex开发者_StackOverflow社区tid = $currid+1;


Yes, and you would use ajax.. the life cycle would go something like this:

  1. Browser requests page

  2. PHP runs and returns html/javascript/css/etc.

  3. javascript runs in browser, using ajax calling a php script on the server

  4. php script returns the results as text or html or json or some other format

  5. javascript takes the results, clears out the old information on the page and puts in the new information

  6. goto 3

There are a ton of javascript libraries out there to help with that part of things. I have used jQuery and highly recommend it.

Update: A simple ajax example:

jQuery(document).ready(function() {
    jQuery.ajax({
        url: 'page.php',
        error: function(jqXHR, textStatus, data) {
            // error
            alert(jqXHR.responseText);
        },
        success: function(data, textStatus, jqXHR) {
            // result
            alert(data);
        }
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜