Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用javascript输出html时出错_Php_Javascript_Html_Ajax - Fatal编程技术网

Php 使用javascript输出html时出错

Php 使用javascript输出html时出错,php,javascript,html,ajax,Php,Javascript,Html,Ajax,我有这段php代码,我试图用它生成一个弹出窗口,其中包含html文件的内容,但是在添加脚本标记后,不会显示html。我试着回显$row2,但是单词数组被打印到屏幕上,其他什么都没有 <?php session_start(); if (isset($_GET["cmd"])) $cmd = $_GET["cmd"]; else die("You should have a 'cmd' parameter in your URL"); $pk = $_GET["pk"]; $con

我有这段php代码,我试图用它生成一个弹出窗口,其中包含html文件的内容,但是在添加脚本标记后,不会显示html。我试着回显$row2,但是单词数组被打印到屏幕上,其他什么都没有

<?php
session_start();
if (isset($_GET["cmd"]))
  $cmd = $_GET["cmd"];
else
  die("You should have a 'cmd' parameter in your URL");
 $pk = $_GET["pk"];
$con = mysql_connect("localhost","root","geheim");
if(!$con)
{
die('Connection failed because of' .mysql_error());
}
mysql_select_db("ebay",$con);
if($cmd=="GetAuctionData")
{
$sql="SELECT * FROM Auctions WHERE ARTICLE_NO ='$pk'";
$sql2="SELECT ARTICLE_DESC FROM Auctions WHERE ARTICLE_NO ='$pk'";
$htmlset = mysql_query($sql2);
$row2 = mysql_fetch_array($htmlset);
echo $row2;
echo '<script> 
function makewindows(){
child1 = window.open ("about:blank");
child1.document.write('.$row2["ARTICLE_DESC"].');
child1.document.close(); 
}
</script>';

$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
echo "<div id='leftlayer'>
    <strong>Article Number</strong> ".$row['ARTICLE_NO']."
    <p><strong>Article Name</strong></p> ".$row['ARTICLE_NAME']."
    <p><strong>Subtitle</strong></p> ".$row['SUBTITLE']."
    <p><strong>Username</strong></p> ".$row['USERNAME']."
    <p><strong>Total Selling</strong></p> ".$row['QUANT_TOTAL']."
    <p><strong>Total Sold</strong></p> ".$row['QUANT_SOLD']."
    <p><strong>Category</strong></p> ".$row['CATEGORY']."
    <p><strong>Highest Bidder</strong></p> ".$row['BEST_BIDDER_ID']."
  </div>
<div class='leftlayer2'>
  <strong>Current Bid</strong> ".$row['CURRENT_BID']."
  <p><strong>Start Price</strong></p> ".$row['START_PRICE']."
  <p><strong>Buyitnow Price</strong></p> ".$row['BUYITNOW_PRICE']."
  <p><strong>Bid Count</strong></p> ".$row['BID_COUNT']."
  <p><strong>Start Date</strong></p> ".$row['ACCESSSTARTS']."
  <p><strong>End Date</strong></p> ".$row['ACCESSENDS']."
  <p><strong>Original End</strong></p> ".$row['ACCESSORIGIN_END']."
  <p><strong>Auction Type</strong></p> ".$row['AUCTION_TYPE']."
</div>
<div class='leftlayer2'>
    <strong>Private Auction</strong></p> ".$row['PRIVATE_AUCTION']."
  <p><strong>Paypal Accepted</strong></p> ".$row['PAYPAL_ACCEPT']."
  <p><strong>Auction Watched</strong></p> ".$row['WATCH']."
  <p><strong>Finished</strong></p> ".$row['FINISHED']."
  <p><strong>Country</strong></p> ".$row['COUNTRYCODE']."
  <p><strong>Location</strong></p> ".$row['LOCATION']."
  <p><strong>Conditions</strong></p> ".$row['CONDITIONS']."
</div>
<div class='leftlayer2'>
  <strong>Auction Revised</strong></p> ".$row['REVISED']."
  <p><strong>Cancelled</strong></p> ".$row['PRE_TERMINATED']."
  <p><strong>Shipping to</strong></p> ".$row['SHIPPING_TO']."
  <p><strong>Fee Insertion</strong></p> ".$row['FEE_INSERTION']."
  <p><strong>Fee Final</strong></p> ".$row['FEE_FINAL']."
  <p><strong>Fee Listing</strong></p> ".$row['FEE_LISTING']."
  <p><a href='#' onclick='makewindows(); return false;'>Click for full description </a></p>
</div>";

$lastImg = $row['PIC_URL'];
echo "<div id='rightlayer'>Picture Picture
<img src=".$lastImg.">
</div>";

}

}
mysql_close($con);
?>

您的
标记永远不会关闭,JavaScript指令也不会以分号结尾。这可能是问题的根源。

您的
标记永远不会关闭,JavaScript指令也不会以分号结尾。这可能是问题的根源。

以及缺少的

child1.document.write('.$row2[“ARTICLE\u DESC”].)
应该是

child1.document.write('.json_encode($row2[“ARTICLE_DESC”])

该函数将为您处理任何报价

编辑:

应该是
-你应该在那里有引号,当你点击链接时,
返回false将阻止你进入“#”


另外,从内存中,我不确定您是否可以打开about:blank然后对其进行写入—我认为它将其视为跨域脚本。您最好在服务器上创建一个最小的“blank.html”文件并使用它。

以及缺少的

child1.document.write('.$row2[“ARTICLE\u DESC”].)
应该是

child1.document.write('.json_encode($row2[“ARTICLE_DESC”])

该函数将为您处理任何报价

编辑:

应该是
-你应该在那里有引号,当你点击链接时,
返回false将阻止你进入“#”


另外,从内存中,我不确定您是否可以打开about:blank然后对其进行写入—我认为它将其视为跨域脚本。您最好在服务器上创建一个最小的“blank.html”文件并使用它。

您必须打印一个数组,如
print\r($row2)

您必须打印数组,如
print\r($row2)

在此行中:

$row2 = mysql_fetch_array($htmlset);
您正在将
$row2
设置为表示查询结果整行的数组。即使“行”只是一个字段,它仍然是一个数组。如果只想获得第一个字段的值,可以使用

参数是:
resource$result,int$row[,mixed$field]
,因此用法示例如下:

// get the first field of the first row
$fieldVal = mysql_result($htmlset, 0);

// get the third field
$fieldVal = mysql_result($htmlset, 0, 2);

// get the first field of the 2nd row
$fieldVal = mysql_result($htmlset, 1);
在这方面:

$row2 = mysql_fetch_array($htmlset);
您正在将
$row2
设置为表示查询结果整行的数组。即使“行”只是一个字段,它仍然是一个数组。如果只想获得第一个字段的值,可以使用

参数是:
resource$result,int$row[,mixed$field]
,因此用法示例如下:

// get the first field of the first row
$fieldVal = mysql_result($htmlset, 0);

// get the third field
$fieldVal = mysql_result($htmlset, 0, 2);

// get the first field of the 2nd row
$fieldVal = mysql_result($htmlset, 1);

将json与ajax混合有什么问题吗?有没有办法避免将临时html文件一直写入服务器..或者如何使用blank.html?我已经修复了您强调的问题,但仍然存在一个脚本错误,它甚至无法加载。JSON和AJAX配合得非常非常好。blank.html只包含一个最小的html页面(doctype,)。然后你可以用javascript编写document.write。没有确切的错误,但我已经粘贴了当前的代码。我不明白为什么会产生错误。将json与ajax混合有问题吗?有没有办法避免将临时html文件一直写入服务器..或者如何使用blank.html?我已经修复了您强调的问题,但仍然存在一个脚本错误,它甚至无法加载。JSON和AJAX配合得非常非常好。blank.html只包含一个最小的html页面(doctype,)。然后你可以使用javascript编写文档。没有确切的错误,但我已经粘贴了当前代码。我不明白为什么会产生错误我现在正在修复这个错误,但我认为错误低于这个错误,因为弹出窗口甚至不会打开我正在修复这个错误,但我认为错误低于这个错误,作为弹出窗口,窗口甚至不会打开