我有一些内容(有些广告)的http地址。比方说,如何通过php请求在html中返回http内容?
http://servername/submit/rest/getHtmlAdvertisements/
我想返回HTML页面上此内容。比方说,在
<div></div>
首先,我必须连接到这个http://
下一个我必须显示的div内容(的jQuery?)。我能做些什么来做到这一点?
我有一些内容(有些广告)的http地址。比方说,如何通过php请求在html中返回http内容?
http://servername/submit/rest/getHtmlAdvertisements/
我想返回HTML页面上此内容。比方说,在
<div></div>
首先,我必须连接到这个http://
下一个我必须显示的div内容(的jQuery?)。我能做些什么来做到这一点?
您可以通过jQuery
使用load()做到这一点:
$("div").load("http://servername/submit/rest/getHtmlAdvertisements/");
或PHP
使用file_get_contents():
<?php
$someData = file_get_contents('http://servername/submit/rest/getHtmlAdvertisements/');
echo "<div>".$someData."</div>";
几种方法,你可以使用PHP curl使网站内容,如:
<?php
function curl_post($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($ch);
curl_close($ch);
return $curl_response;
}
$content = curl_post('http://servername/submit/rest/getHtmlAdvertisements/');
?>
现在你必须修改<div></div>
代码下面显示的内容:
<div><?php echo $content; ?></div>
或者使用file_get_contents,如:
<?php
$content = file_get_contents('http://servername/submit/rest/getHtmlAdvertisements/');
echo $content;
?>