我有一个小问题。因此,我使用 Ajax 将另一个页面的内容加载<div>
到<select>
. 但问题是,我只想<div>
将该外部页面中的特定内容加载到我的主页中。这是主页的代码:
<script type="text/javascript">
$(function(){
createListeSelectWithDefault("categorie", <?php echo getJsCategorieListe()?>);
});
function showListes(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","liste_result?q="+str,true);
xmlhttp.send();
}
</script>
<div id="content">
<div id="bloc">
<div id="title">Combiner</div>
<div class="mx">
<form name="new_combiner">
<select id="categorie" name="categorie" onchange="showListes(this.value)"></select>
</form>
</div>
<div class="mx">
<div id="txtHint">
</div>
</div>
</div>
</div>
这是我的外部页面:
<html>
<div> some other kind of text, no need to post it here, but can't take it away</div>
<div id="mainDiv">
<?php
$q=$_GET["q"];
$liste = getListeByCategorie($q);
echo "<table border='1'>
<tr>
<th>Titre</th>
<th>Vues</th>
</tr>";
foreach($liste as $row)
{
echo "<tr>";
echo "<td>" . $row->titre() . "</td>";
echo "<td>" . $row->vue() . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</div>
<div> some other kind of text, no need to post it here, but can't take it away</div>
所以你去,仅此而已。我该怎么办?我只想<div id="mainDiv">
将 加载到我的页面中。