/    Sign up×
Community /Pin to ProfileBookmark

[AJAX] why am i randomly losing data in IE?

heres the deal. heres my site:

[url]http://webfiles.dreamhosters.com/qm[/url]

in that site, essentially, i have 3 pages in my ajax program:

[URL=”http://webfiles.dreamhosters.com/qm/”]index.php[/URL] – the page that runs the AJAX
[URL=”http://webfiles.dreamhosters.com/qm/list_get.php”]list_get.php[/URL] – first ajax page called. outputs some debug info. stores IPs and PORTS into a (PHP) session variable
[URL=”http://webfiles.dreamhosters.com/qm/list_show.php”]list_show.php[/URL] – second ajax page called. runs php queries in the background against the stored IPs and PORTS. outputs the results of the queries; said output resembles the syntax that would otherwise declare javascript arrays

so for example, index.php fires off this ajax scripting:

[code]function getList()
{
if(refresh == -1)
refresh = 0;
else if(refresh == 1)
{
refresh =0;
document.getElementById(“refresh”).innerHTML = “<img src=”images/refresh_all_2.jpg” title=”Retrieving server list…”>”;
}
else
return;

xmlHttp = GetXmlHttpObject();

if(xmlHttp==null)
{
alert (“Your browser does not support AJAX!”);
return;
}

var url = “list_get.php?sid=” + Math.random();

xmlHttp.onreadystatechange = getListChanged;
xmlHttp.open(“GET”,url,true);
xmlHttp.send(null);
}

function getListChanged()
{
if (xmlHttp.readyState==4)
{
response = xmlHttp.responseText.split(“n”);

for(x in response)
output += response[x] + “<br>”; // debug info is displayed

document.getElementById(“writehere”).innerHTML = output;

serverInfo();
}
}
[/code]

the innerHTML stuff is just outputting the debug info. then my next ajax request is called via serverInfo():

[code]function serverInfo()
{
xmlHttp = GetXmlHttpObject();

if(xmlHttp == null)
{
alert (“Your browser does not support AJAX!”);
return;
}

var url = “list_show.php?sid=” + Math.random();

xmlHttp.onreadystatechange = serverInfoChanged;
xmlHttp.open(“GET”,url,true);
xmlHttp.send(null);

theStart = new Date().valueOf();
}
var serverArray = new Array(); // [B]NOTICE THIS IS IN GLOBAL CONTEXT[/B]

function serverInfoChanged()
{
document.getElementById(“content”).innerHTML += “waiting for a response..<br>”

if(xmlHttp.readyState==4)
{
refresh = 1;

var theVal = new Date().valueOf();
var split = theVal – theStart;

// all we are doing is making it look nice here
document.getElementById(“content”).innerHTML += xmlHttp.responseText.replace(/);/g,”);<br>”);

// remove apostrophes from the array or else it breaks
var theoutput = xmlHttp.responseText.replace(/’/g,””)

// output the raw response we got from list_show.php
document.getElementById(“writehere”).innerHTML += “<br><br>” + xmlHttp.responseText

// actually try and run the apostrophe replace info
eval(theoutput)

// at this point, if an error occurs, it was because of data loss
}
}[/code]

i was thinking that “list_get.php” and the PHP was the culprit, but when i copy all the text from that page “list_get.php” (by directly navigating to it), and then sticking it in the code below:

[code]
<script>
var serverArray = new Array()

// i place the copied text here

alert(“done.”)
</script>[/code]

i never have a problem getting the alert to fire. so the PHP cant possibly be the one dropping data sporadically. something is being lost during ajax transmission.

any idea why i would be getting this sporadic data loss? this only occurs in IE from what ive seen. navigate to my link above to test. if you get a prompt after all that array garbage is printed to that table, the code executed succesfully. SOMETIMES IE doesnt fail.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Angry_Black_ManauthorAug 23.2007 — how disappointing. i wanted to follow some good advice in regards to breaking up ajax output by passing back array syntax to my ajax call. that way, instead of having to split the information to create array information based on the existence of some character i have to artificially insert, i wanted to do something more elegant.

but becuase IE, in all its flaws, refuses to cooperate, i had to add that artificial character, break the arrays with a split, then individually eval each index. that way, i could just throw out the one array that ended up screwed up.
×

Success!

Help @Angry_Black_Man spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...