loveccb Posted July 26, 2011 Share Posted July 26, 2011 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+'×tamp='+(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. } Quote Link to comment https://forums.phpfreaks.com/topic/242853-ajax-call-running-twice/ Share on other sites More sharing options...
requinix Posted July 26, 2011 Share Posted July 26, 2011 Are you sure you posted the actual code you have? I'm not. There are a few problems with it that break the script. Quote Link to comment https://forums.phpfreaks.com/topic/242853-ajax-call-running-twice/#findComment-1247456 Share on other sites More sharing options...
loveccb Posted July 26, 2011 Author Share Posted July 26, 2011 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+'×tamp='+(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> Quote Link to comment https://forums.phpfreaks.com/topic/242853-ajax-call-running-twice/#findComment-1247462 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.