包括网页中远程php脚本的输出

时间:2011-08-10 16:04:56

标签: php jquery html widget

我有一个驻留在远程服务器上的php脚本。我试图将该脚本的输出包含在运行了一些jquery的网页中,制作一个小部件。

<?php
include('includes/include.php');
//date play
$today = date('Y-m-d');

//run query to find today's events
$query = "SELECT e.*, l.* FROM hc_events e
   LEFT JOIN hc_locations l ON (l.PkID = e.LocID)
   WHERE e.IsActive = 1 AND e.IsApproved = 1 AND e.StartDate >= '". $today ."' 
   ORDER BY e.SeriesID, e.SubmittedAt, e.StartDate, e.Title
   LIMIT 0, 5";

$result = doQuery($query);
while($row = mysql_fetch_array($result)){

  //print_r($row);

  if($row['LocationName'] && $row['LocationAddress'] && $row['LocationCity'] && $row['LocationCity']){
    $locationInfo = $row['LocationName'] . ', ' . $row['LocationAddress'] . ' ' . $row['LocationAddress2'] . ' ' . ucwords($row['LocationCity']) . ', ' . $row['LocationZip'];
  }
  else{
    $locationInfo = $row['Name'] . ', ' . $row['Address'] . ' ' . $row['Address2'] . ' ' . ucwords($row['City']) . ', ' . $row['Zip'];
  }


  $contactInfo = $row['ContactName'] . ' -- ' . $row['ContactEmail'] . ', ' . $row['ContactPhone'];
  ?> 

  <fieldset class="collapsible collapsed">
  <legend><?php echo $row['Title']; ?></legend>
  <p><?php echo date("g:i ", strtotime($row['StartTime']))?>&mdash;<?php echo " " . date("g:i ", strtotime($row['EndTime']))?></p>
  <p><?php echo $row['Description']; ?></p>
  <p><?php echo $locationInfo; ?></p>
  <p><?php echo $row['Cost'];?></p>
  <p><?php echo $contactInfo; ?></p>
  </fieldset>
<?php  
}
?>

我已经尝试将所有内容都放在显示页面上的iframe中,它可以正常运行,但它会抛出jquery。所以基本上我是由php输出的html,就像在小部件页面上一样。我试图做一些像widget.js包含的地方:

document.write('<php include(path/to/widget.php); ?>');

有人知道这样做的正确方法吗?

1 个答案:

答案 0 :(得分:0)

您需要引用远程页面的URL,而不是远程页面的PHP脚本的路径:

$("#whatever").load("http://remote-server.com/your_script.php");