Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    xmlhttp doesn't update

    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:

    Code:
    //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;
    }
    Code:
    //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.

  • #2
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Please help

  • #3
    Banned
    Join Date
    Mar 2009
    Posts
    248
    Thanks
    3
    Thanked 68 Times in 66 Posts
    RaptorIV:

    It might help if you included the "please" in the initial post.

    Code:
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
    xmlhttp.send(null);
    Last edited by 12 Pack Mack; 07-27-2009 at 09:48 PM.

  • #4
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    haha, I'll remember that next time. Now it just gives me an "Unspecified Error" in IE. Works in firefox still though.

  • #5
    Banned
    Join Date
    Mar 2009
    Posts
    248
    Thanks
    3
    Thanked 68 Times in 66 Posts

  • #6
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Adding a setRequestHeader stops it from working on firefox and causes an error on IE. I added header information to the php page but that didn't do anything.
    Still have that same problem

  • #7
    Banned
    Join Date
    Mar 2009
    Posts
    248
    Thanks
    3
    Thanked 68 Times in 66 Posts
    Code:
    var forceGET = "?n="+ parseInt(Math.random()*999999999);
    cityRequest.open("GET", "WeatherFiles/Cities.xml"+forceGET, true);
    cityRequest.send(null);

  • Users who have thanked 12 Pack Mack for this post:

    RaptorIV (07-27-2009)

  • #8
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you!

  • #9
    Banned
    Join Date
    Mar 2009
    Posts
    248
    Thanks
    3
    Thanked 68 Times in 66 Posts
    My initial post had the setRequestHeader out of order.

    You really should use that and not a random number.

    I corrected my initial post.

    The setRequestHeader comes after "open".

  • #10
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi all, sorry to pull up what appears to be an ancient thread, but I'm am having the same caching issue using IE. I'm not clear as how to remediate it based on the above (sorry, somewhat new to JS).
    Where should setRequestHeader come in my case below (somewhat elementary I know):


    Code:
     var client = new XMLHttpRequest();
    client.open('GET', 'http://localhost:8080/file.txt');
    client.send();
    	 var inputtxt = client.responseText;
    Thanks in advance


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •