2015-10-02 103 views
0

我已经看过很多例子,但它们似乎都称为“.php”文件。Ajax Div在5秒后重新加载

我想要做的是逻辑上相当简单。

我需要自动刷新一个包含PHP的div来获取mysql数据。

有没有反正这样做,而无需调用另一个.php文件。

div名称:#autoload

<div id="autoload">phpdata</div> 

回答

0

据我所知,这是不可能的,我不建议做任何这样的说法。

最好将您的PHP代码分成另一个文件,然后用AJAX请求该文件。

+0

宕,好的,谢谢:) – Venom791

+0

[这里](http://stackoverflow.com/questions/20351075/how-to-call-the-ajax-page-in-same-page)或[here](http://stackoverflow.com/questions/7561569/jquery-ajax-passing-value-on-php-相同页面)或[这里](http://stackoverflow.com/questions/4060714/ajax-request-to-same-page) – Chris

0

如果我是正确的,您正尝试每5秒刷新一次具有新内容的特定div。一种解决方案可能是使用JavaScript的setInterval喜欢:

的JavaScript

function refreshContent() { 
    $.ajax({ 
     url: '/echo/json/' //here is the php file that returns the new data 
    }).done(function() { 
     $("#autoload").append("new content") 
    }); 
} 

setInterval(refreshContent, 5000); 

fiddle