Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AJAX refresh page error 1

Status
Not open for further replies.

thompom

Technical User
Dec 4, 2006
395
GB
Hi,

Have the following script that works fine on first load
but if i refresh the page i get

[object Error]

page that calls AJAX func
Code:
<script type="text/javascript" src="AJAX.js"></script>
<!--start cal-->
<div id="cal">
</div>
<!--end cal-->
<script type="text/javascript">
sndSORT();
</script>

AJAX.js script
Code:
<!--
// Written by Dexter Zafra at [URL unfurl="true"]www.ex-designz.net[/URL]
//Handle Check Username Availability Using Ajax
 var http = createRequestObjectHIT();
 function createRequestObjectHIT() 
     {
           var xmlhttp;
	 try 
                 { 
                    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
                 }
	  catch(e) 
                 {
	    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	    catch(f) { xmlhttp=null; }
	    }
	        if(!xmlhttp&&typeof XMLHttpRequest!="undefined") 
                        {
	  	   xmlhttp=new XMLHttpRequest();
	           }
		   return  xmlhttp;
 }

function sndSORT() 
 {
            try
              {
http.open('GET', 'PAGE.asp');                

http.onreadystatechange = handleResponseTextSORT;
	    http.send(null);
	 }
	    catch(e){}
	    finally{}
 }
function handleResponseTextSORT() 
  {
     try
         {
             if((http.readyState == 4)&& (http.status == 200))
                {
    	          var response = http.responseText;
	
                 var grnelement = document.getElementById('cal');
                 grnelement.innerHTML = response;
      
	        }
        }
	catch(e){alert(e);}
	finally{}
}

PAGE.asp just has a response.write ("hello")
 
[1] First thing first.
>sndSORT();
[tt]window.onload=sndSORT;[/tt]
so as to make sure that the body is loaded.

[2] Then you can force each time fetching the PAGE.asp anew when refreshed or by other mechanism. One method is to append a random query (one way to make it is shown below) to the page.
>http.open('GET', 'PAGE.asp');
[tt]http.open('GET', 'PAGE.asp' + [blue]'?' + (new Date()).valueOf()[/blue]);[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top