Ajax:Javascript无法从服务器响应中显示html代码

Ajax:Javascript无法从服务器响应中显示html代码,javascript,html,ajax,Javascript,Html,Ajax,我目前正在尝试使用ajax在站点中创建搜索机。我希望结果以以下格式显示在我的主页中: <div id="searchResults"></div> 标签内的文本-结果-在我的页面中正常传递,但无法显示。相反,它似乎是“未定义”一词 有人能帮我解决这个问题吗?佩法普斯,有没有更简单的方法来实现我的目标 提前感谢您的时间 我在这里看到错误str=“”应为$str=”“。不确定它是否能解决您的问题,但如果您的查询没有返回任何行,它就会解决。对不起,我的错误。。我没有抄对。

我目前正在尝试使用ajax在站点中创建搜索机。我希望结果以以下格式显示在我的主页中:

<div id="searchResults"></div>  
标签内的文本-结果-在我的页面中正常传递,但无法显示。相反,它似乎是“未定义”一词

有人能帮我解决这个问题吗?佩法普斯,有没有更简单的方法来实现我的目标


提前感谢您的时间

我在这里看到错误
str=“”应为
$str=”“。不确定它是否能解决您的问题,但如果您的查询没有返回任何行,它就会解决。对不起,我的错误。。我没有抄对。在我的代码中,有一个美元符号。我在这里看到错误
str=“”应为
$str=”“。不确定它是否能解决您的问题,但如果您的查询没有返回任何行,它就会解决。对不起,我的错误。。我没有抄对。在我的代码中,有一个美元符号。
<div id='product_box'>
   <h2 style='color: blue'>Result 1</h2>
   <b style='text-decoration: underline'>Price:</b> <b style='color: red'> 500 Euros</b><br><br>
   <b style='text-decoration: underline'>Description:</b> <b style='font-style: italic'>mpla mpla mpla</b>      
</div>; 
<?php
/*---Interaction with the database---*/
$response = '<?xml version="1.0" encoding="UTF-8"?>';
$response .= '<response>';
$response .= '<numOfResults>' . $numOfProducts . '</numOfResults>';
$response .= '<maxNumOfProducts>' . $maxNumOfProducts . '</maxNumOfProducts>';

str = "";

while ($productsOfTheSearch = mysqli_fetch_array($query_select_products))
{
    $product_id = $productsOfTheSearch['product_id'];
    $product_title = $productsOfTheSearch['product_title'];
    $product_price = $productsOfTheSearch['product_price'];
    $product_desc = $productsOfTheSearch['product_desc'];

    $str .= "
        <div id='product_box'>
   <h2 style='color: blue'>$product_title</h2>
   <b style='text-decoration: underline'>Price:</b> <b style='color: red'> $product_price Euros</b><br><br>
   <b style='text-decoration: underline'>Description:</b> <b style='font-style: italic'>$product_desc</b>       
        </div>; 
        ";
}

$response .= '<results>' . $str . '</results>';

$response .= '</response>'; 
$response .= '</xml>';  

echo $response;

?>
//Preparation functions... xmlHttp is the object from the XMLHttpRequest().
function handleServerResponse()
{
   if(xmlHttp.readyState==4 && xmlHttp.status==200)
   {
        response = (new DOMParser()).parseFromString(xmlHttp.responseText,'text/xml');

        x = response.getElementsByTagName("numOfResults");
        numOfResults = x[0].firstChild.data;
        x = response.getElementsByTagName("maxNumOfProducts");
        maxNumOfProducts = x[0].firstChild.data;

        //things with numOfResults and maxNumOfProducts.
        //These work fine!!!

        x = response.getElementsByTagName("results");

        document.getElementById("searchResults").innerHTML = x[0].firstChild.data

        setTimeout('searchFunction()', 200);

   }
}