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.
}