Jump to content

Recommended Posts

Hello all.  My AJAX object is running twice.  I've done my best to debug it, but I seem to be missing something.

 

The ajax page (getsummarydecision.php) loads simply sends an email and returns an image.  When I run this page separately, only one email is sent.  When I run this AJAX object, 2 emails are sent.  Does anyone see anything obvious here? 

 

The html:

<div id="div_gauge"></div>

<script type="text/javascript">

var dec_gauge = new AJAXobject('gauge','div_gauge');
dec_gauge.update('id=100');
</script>

 

The javascript:

function AJAXobject(div,type) {	//javascript object that checks the report status of each ordered report and displays status in page div
var that=this;
var updating = false;
//this.callback = function() {alert("timestamp " + timestamp);} 

 if (type == "gauge") {
	//Set url
	var url = "common/getsummary.php";

    var div_decision = document.getElementById(div);	    
    div_decision.innerHTML = "Calculating... <img src=\"images/ajax-loader.gif\" />";
}

    
//Update function
    this.update = function(passData) {                                
        if (updating==true) { return false; }                          
        updating=true;                                               
        var AJAX = null; 

   if (window.XMLHttpRequest){
		AJAX = new XMLHttpRequest();
   }else if (window.ActiveXObject){
	   AJAX = new ActiveXObject("Microsoft.XMLHTTP");
   }
   
   if (AJAX==null) {                                            
         alert("Your browser doesn't support AJAX.");                                                       
         return false;                                             
   } 
   else {
	   AJAX.onreadystatechange = function() {                      
            if (AJAX.readyState==4 && AJAX.status==200) {
			   LayerID.innerHTML=AJAX.responseText;                 
			   delete AJAX;                                         
                           updating=false;                                 
                                   that.callback();   
                     }                                                        // End Ajax readystate check.
         }  
	                            	
      var timestamp = new Date().getTime();

	  var uri=urlCall+'?'+passData+'&timestamp='+(timestamp*1);   

		AJAX.open("POST", uri, true);                              
         AJAX.send(null);                                          
         return true;                                             
   }   
    } //end update function  


//-----------------------------------------------------
   var LayerID = document.getElementById(div);                     // the layer associated with this object.
   var urlCall = url;                                                                   // the url associated with this object.
   
}

Link to comment
https://forums.phpfreaks.com/topic/242853-ajax-call-running-twice/
Share on other sites

Yes, you're correct requinix.  I tried to summarize and inadvertently broke my own code.  As it is:

 

<html>
<head>
<script type="text/javascript">	

	function AJAXobject(div,type) {	//javascript object that checks the report status of each ordered report and displays status in page div
		var that=this;
		var updating = false;
		//this.callback = function() {alert("timestamp " + timestamp);} 

	 if (type == "gauge") {
		//Set url
		var url = "common/getsummary.php";

		var div_decision = document.getElementById(div);	    
		div_decision.innerHTML = "Calculating... <img src=\"images/ajax-loader.gif\" />";
	}


	//Update function
	this.update = function(passData) {                                
		if (updating==true) { return false; }                          
		updating=true;                                               
		var AJAX = null; 

	   if (window.XMLHttpRequest){
			AJAX = new XMLHttpRequest();
	   }else if (window.ActiveXObject){
		   AJAX = new ActiveXObject("Microsoft.XMLHTTP");
	   }
	   
	   if (AJAX==null) {                                            
			 alert("Your browser doesn't support AJAX.");                                                       
			 return false;                                             
	   } 
	   else {
		   AJAX.onreadystatechange = function() {                      
				if (AJAX.readyState==4 && AJAX.status==200) {
				   LayerID.innerHTML=AJAX.responseText;                 
				   delete AJAX;                                         
				   updating=false; 					
				   //that.callback();   
				 }                                                        // End Ajax readystate check.
			 }  

		  var timestamp = new Date().getTime();

		  var uri=urlCall+'?'+passData+'&timestamp='+(timestamp*1);   

			AJAX.open("POST", uri, true);                              
			 AJAX.send(null);                                          
			 return true;                                             
	   }   
	} //end update function  


	//-----------------------------------------------------
	   var LayerID = document.getElementById(div);                     // the layer associated with this object.
	   var urlCall = url;                                              // the url associated with this object.
	   
}
</script>
</head>
<body>
<div id="div_gauge"></div>
<script type="text/javascript">	
	var dec_gauge = new AJAXobject('div_gauge','gauge');
		dec_gauge.update('id=100');
</script>
</body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.