/    Sign up×
Community /Pin to ProfileBookmark

xml; mozilla; load xml file issue

Hey guys!

I have the following code for loading an external XML file.
In IE thisworks fine as does the rest of the script, but in FF then focus is passed back to the function caller before the xml document has finished loading, and so not passing back the array that it should.

Any suggestions?

Thanks,
//erlin!

[code=php]
function getConfigBlockArray(rf)
{
var blockArray = new Array();

if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject(“Microsoft.XMLDOM”);
xmlDoc.async = false;
xmlDoc.load(rf);
blockArray = xmlSectionToArr(xmlDoc);
return blockArray;

}
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument(“”, “”, null);
xmlDoc.load(rf);
xmlDoc.onload = function()
{
blockArray = xmlSectionToArr(xmlDoc);
return blockArray;
}
}
}
[/code]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@jsakalosJun 10.2007 — Does Firebug show any errors?
Copy linkTweet thisAlerts:
@Mega69Jun 10.2007 — Maybe you've been trying to do domething like that:
<i>
</i>myArray=getConfigBlockArray(rf);


You can use the array only inside the onload handler:
<i>
</i>xmlDoc.onload = function()
{
blockArray = xmlSectionToArr(xmlDoc);
doSomething(blockArray);
}
Copy linkTweet thisAlerts:
@CrazyMerlinauthorJun 11.2007 — there are no errors, and the scope of the array is not an issue either.

the problem is that the document is loading asynchronously instead of synchronously, so the load function is returning before the document is loaded.

what I need is to make sure that the document is loaded before the function returns.

I have set async to false, but this makes no different whatsoever.

like I said, it works as it should in IE, so I think it may be something to do with the implementation in FF.

thanks.
Copy linkTweet thisAlerts:
@UltimaterJun 11.2007 — xmlDoc.async is understood in Firefox as well as IE :p
<i>
</i>xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.async = false;
xmlDoc.load(rf);


It should be noted however that Sjax requests will put JavaScript on halt until the request resolves and things like user-triggered events will be ignored until the request resolves. For this reason pros will avoid Sjax while Ajax can be properly used even if it means writing extra coding.
Copy linkTweet thisAlerts:
@CrazyMerlinauthorJun 11.2007 — yeah, I agree Ulti

I will have to re-design my code...no biggie!

thanks.
×

Success!

Help @CrazyMerlin 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.18,
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,
)...