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:
Browser requests page
PHP runs and returns html/javascript/css/etc.
javascript runs in browser, using ajax calling a php script on the server
php script returns the results as text or html or json or some other format
javascript takes the results, clears out the old information on the page and puts in the new information
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);
}
});
});
精彩评论