get_file_contents刷新DIVget_file_contents、DIV

2023-09-10 20:15:15 作者:有性心才会淫   &

我装使用PHP的 get_file_contents 内容到一个div, 现在我想用ajax刷新,但我不明白怎么做了。

样品code:

 <脚本>
功能refreshmydiv(){
...
}
< / SCRIPT>

< D​​IV ID =mydiv> &LT ;?回声nl2br(用htmlspecialchars($ MYFILE)); ?> < D​​IV>
< A HREF =#的onclick =refreshmydiv();>刷新我的事业部< / A>
 

解决方案

所以,在这里是做这件事的一种方式。首先,将部分:

myrefreshfunction

此功能需要作出一个AJAX调用 refresh.php 或其他页面。然后,它应该被发回的HTML代替 mydiv 的内容。

refresh.php

php file get contents 写好后为什么不跳转到指定页面

本页面需要返回的HTML DIV。它并不需要返回整个网页,它仅需要返回div的内容

在这种情况下,它只是回声 get_file_contents ,别无其他。

恩。

 < PHP
$网页=的file_get_contents('http://www.example.com/');
回声$的主页;
?>
 

然后,刷新过程是这样的:

您的用户presses按钮刷新DIV。

您的函数请求一个页面。

页面返回的div唯一的内容。

您的函数替换它只是请求的页面的div的内容。

有其他方法可以做到这一点,就把这是一个非常简单的方法来做到这一点。

如果你使用jQuery,你的 myrefreshfunction 基本上是一条线的code:

  $('mydiv')负载('refresh.php');
 

I loaded a content into a div using php get_file_contents, now i want to refresh it using ajax but i can't figure how to do it.

Sample code:

<script>
function refreshmydiv(){
...
}
</script>

<div id="mydiv"> <? echo nl2br(htmlspecialchars($myfile)); ?> <div>
<a href="#" onclick="refreshmydiv();">Refresh My Div</a>

解决方案

So, here is one way of doing it. First, the parts:

myrefreshfunction

This function needs to make an AJAX call to refresh.php or another page. Then, it should replace the contents of mydiv with the html that is sent back.

refresh.php

This page needs to return the HTML for the div. It doesn't need to return the whole page, it only needs to return the contents of the div.

In this case, it would just echo get_file_contents and nothing else.

ex.

<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>

Then, the refresh process looks like this:

Your user presses the button to refresh the div.

Your function requests a page.

The page returns ONLY the contents of the div.

Your function replaces the content of the div with the page it just requested.

There are other ways to do this, put this is a very straightforward way to do it.

If you use jQuery, your myrefreshfunction is basically one line of code:

$('mydiv').load('refresh.php');