Can anyone check out this script? My ajax code doesn't run and the xmlhttp.status is always 0 though it is always 200 in my other scripts. I am sure there is something wrong with my script. Can anyone help me fix it? I tried to debug it for hours but couldn't fix it :(
<?php
require '../includes/connect.inc.php';
?>
<style type='text/css'>
@import url('../styles/pagestyle.css');
</style>
<div id='result'><p class='basicbox'>You can add a maximum of 10 menus. Keep a menu blank if you don't need it.</p></div>
<?php
$query = "SELECT `link_name`,`page_id` FROM `onwebed_menu` WHERE 1";
if ($mysql_query = mysql_query($query)){
if (mysql_num_rows($mysql_query)>=1){
$i = 1;
while($mysql_row = mysql_fetch_assoc($mysql_query)){
?>
<div id='basicdiv'>
<span><?php echo $i." "; ?><input type='text' id='linkname<?php echo $i; ?>' value="<?php echo $mysql_row['link_name']; ?>" class='textboxbasic'>
<input type='text' id='pageid<?php echo $i; ?>' value="<?php echo $mysql_row['page_id']; ?>" class='textboxbasic'></span><br>
</div>
<?php
$i++;
}
}else{
die('No results found');
}
}else{
die("There was an error");
}
?>
<p></p><input type='button' value='Save Changes' class='submitbutton' onclick="editmenu('result','editmenu.inc.php');"/>
<script type='text/javascript'>
function editmenu(id, file){
if (window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
xmlhttp = new ActiveXObject('Microsoft.XMLHttp');
}
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById(id).innerHTML = xmlhttp.responseText;
}
}
var linkname1 = document.getElementById('linkname1').value;
var linkname2 = document.getElementById('linkname2').value;
var linkname3 = document.getElementById('linkname3').value;
var linkname4 = document.getElementById('linkname4').value;
var linkname5 = document.getElementById('linkname5').value;
var linkname6 = document.getElementById('linkname6').value;
var linkname7 = document.getElementById('linkname7').value;
var linkname8 = document.getElementById('linkname8').value;
var linkname9 = document.getElementById('linkname9').value;
var linkname10 = document.getElementById('linkname10').value;
var pageid1 = document.getElementById('pageid1').value;
var pageid2 = document.getElementById('pageid2').value;
var pageid3 = document.getElementById('pageid3').value;
var pageid4 = document.getElementById('pageid4').value;
var pageid5 = document.getElementById('pageid5').value;
var pageid6 = document.getElementById('pageid6').value;
var pageid7 = document.getElementById('pageid7').value;
var pageid8 = document.getElementById('pageid8').value;
var pageid9 = document.getElementById('pageid9').value;
var pageid10 = document.getElementById('pageid10').value;
var querystring = "linkname1="+linkname1+"&linkname2="+linkname2+"&linkname3="+linkname3+"&linkname4="+linkname4+"&linkname5="+linkname5+"&linkname6="+linkname6+"&linkname7="+linkname7+"&linkname8="+linkname8+"&linkname9="+linkname9+"&linkname10="+linkname10;
xmlhttp.open('POST', file, true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(querystring);
}
</script>