RaptorIV
07-27-2009, 08:07 PM
I'm using an xmlhttp request to get information from a database. Everything works fine in Firefox, and it works in IE until you try to refresh the page. If a news post (thats what it is getting from the database) is deleted it will continue to show the same information.
I can't really post all of the script because it (along with the html and php) are spread out through many different pages:
//JS
var xmlhttp;
function refreshNews()
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="library/admin_processnews.php?access=1&show_news=1";
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function deleteNews(id)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="library/admin_processnews.php?access=1&show_news=1&do=delete_news&delete="+id;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
alert(xmlhttp.responseText);
document.getElementById("news").innerHTML=xmlhttp.responseText;
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
//PHP
<?
require("dbconnect.php");
if($_GET['access']==1){
switch($_GET['do']){
case 'post_news':
@mysqli_query($con, 'INSERT INTO news (title, date, content) VALUES ("'.$_GET['title'].'", "'.date('m/d/Y').'", "'.$_GET['content'].'")') or die("Couldn't post announcement: ".mysqli_error());
break;
case 'delete_news':
@mysqli_query($con, "DELETE FROM news WHERE id=".$_GET['delete']) or die("Couldn't delete Announcement: ".mysqli_error());
$query = mysqli_query($con, "SELECT * FROM news ORDER BY id Desc") or die(mysql_error());
break;
default:
}
}
if($_GET['show_news']==1){
$query = mysqli_query($con, "SELECT * FROM news ORDER BY id Desc") or die(mysql_error());
while ($row = mysqli_fetch_assoc($query)) {
if($_GET['access']==1){
echo "<h1>".$row['title']." <a href='#' onClick=deleteNews(".$row['id'].")>(Delete)</a></h1>";
}else{
echo "<h1>".$row['title']."</h1>";
}
print "<h2>".$row['date']."</h2>";
echo "<p>".$row['content']."</p>";
}
}
?>
refreshNews() is called in the onLoad event of the body in the html.
I can't really post all of the script because it (along with the html and php) are spread out through many different pages:
//JS
var xmlhttp;
function refreshNews()
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="library/admin_processnews.php?access=1&show_news=1";
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function deleteNews(id)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="library/admin_processnews.php?access=1&show_news=1&do=delete_news&delete="+id;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
alert(xmlhttp.responseText);
document.getElementById("news").innerHTML=xmlhttp.responseText;
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
//PHP
<?
require("dbconnect.php");
if($_GET['access']==1){
switch($_GET['do']){
case 'post_news':
@mysqli_query($con, 'INSERT INTO news (title, date, content) VALUES ("'.$_GET['title'].'", "'.date('m/d/Y').'", "'.$_GET['content'].'")') or die("Couldn't post announcement: ".mysqli_error());
break;
case 'delete_news':
@mysqli_query($con, "DELETE FROM news WHERE id=".$_GET['delete']) or die("Couldn't delete Announcement: ".mysqli_error());
$query = mysqli_query($con, "SELECT * FROM news ORDER BY id Desc") or die(mysql_error());
break;
default:
}
}
if($_GET['show_news']==1){
$query = mysqli_query($con, "SELECT * FROM news ORDER BY id Desc") or die(mysql_error());
while ($row = mysqli_fetch_assoc($query)) {
if($_GET['access']==1){
echo "<h1>".$row['title']." <a href='#' onClick=deleteNews(".$row['id'].")>(Delete)</a></h1>";
}else{
echo "<h1>".$row['title']."</h1>";
}
print "<h2>".$row['date']."</h2>";
echo "<p>".$row['content']."</p>";
}
}
?>
refreshNews() is called in the onLoad event of the body in the html.