There isn't enough code to run things and make sure it works, but I believe this is what you want.
Notice the use of request.abort
. I also changed the strings in setTimeout
to proper functions.
function letsDoIt(seqV, aPrV, aAdsV, xV) {
if (pt() == "auto") {
sequence = seqV;
properties = aPrV;
ads = aAdsV;
position = xV;
//Set picture in place.
charV = sequence[position].left(1);
_L("Next thing is " + sequence[position]);
switch (sequence[position].left(1)) {
case "A":
//Show ad
break;
case "P":
//Show property
break;
case "W":
_L("Auto: Showing weather");
$("#adOrProp").val("W");
($("#footer").css("top") != "1008px") && $("#footer").animate({
"top": "1008px"
}, 375); //500
$("#property-auto").css("background-image", "url(images/pool.jpg)").css("background-position", "top center").css("background-size", "cover");
//Important Vars
var weatherCode = "874";
var weatherInt = 'aploc';
var length = 30e3; // length of weather (s)
var timeSet = length;
var feedURL = 'http://specific-domain.com/rss/wx.php?u=13145[amp]lt=' + weatherInt + '[amp]lc=' + weatherCode + '[amp]obs=1[amp]fc=1[amp]warn=1';
var cfmParser = (0 == 1) ? 'http://other-specific-domain.com/rssparser-usa.cfm' : 'http://other-specific-domain.com/rssparser.cfm';
var parserString = cfmParser + '?url=' + feedURL;
var request;
function parseXML(val) {
if (document.implementation && document.implementation.createDocument) {
xmlDoc = new DOMParser().parseFromString(val, 'text/xml');
} else if (window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.loadXML(val);
} else {
alert("Your browser can't handle this script.");
return null;
}
return xmlDoc;
}
function callback() {
if (request.readyState == 4) {
try {
if (request.status == 200) {
var ajaxData = request["responseText"];
var xmlDoc = parseXML(ajaxData);
try {
//various formatting
} catch (e) {
alert("ERR:" + e.message);
}
//other various things
} else {
return false;
}
} catch (e) {
return false;
}
}
}
request = new CrossXHR();
request.target = 'test';
request.onreadystatechange = callback;
var timeOut = window.setTimeout(function () {
if (document.getElementById('icon-first').src.right(19) == 'images/icons/na.png') {
request.abort();
// Re-call the function to get the ball rolling again?
// Or whatever else you'd like to do.
letsDoIt(seqV, aPrV, aAdsV, xV)
}
}, 400);
request.open('GET', parserString);
request.send();
break;
}
position = (position + 1) % sequence.length;
p_id = auto_i = addy = null;
setTimeout(function() {
letsDoIt(sequence,properties,ads,position);
}, timeSet + iAPT * 2 + 2);
}
}