I'm using ajax for some dynamic aspect of my site's detail page, but I have unsual results. It appears when I perform my open call which looks like.
<script>
function showRSS(str) {
if (str.length==0) {
document.getElementById("rssOutput").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("rssOutput").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",'?page=condition&q=' + str,true);
xmlhttp.send();
}
</script>
<body>
<form>
<input name="format" type="radio" onclick="showRSS(this.value)" value="hardcover" />
<input name="format"type="radio" onclick="showRSS(this.value)" value="paperback" />
</form>
<br>
<div id="rssOutput">RSS-feed will be listed here...</div>
My entire website gets duplicated again.
The condition page is:
<?php
$q=$_GET["q"];
//find out which feed was selected
if($q=="hardcover") {
echo 'hardcover';
}else{
echo'paperback';
}
?>
You need to specify the URL of condition.php
in the xmlhttp.open()
call:
xmlhttp.open("GET", 'condition.php?q='+str, true);
Since you didn't have the page URL, it defaulted to the current page's URL. Your index page uses the page=XXX
parameter to embed the contents of that sub-page into it. But you don't want to go to the index page with AJAX, you just want the sub-page by itself.