var field1; var field2; function setUserFields() { $.ajax({ type: "POST", url: "url", dataType: "xml", complete: parseXml }); } function parseXml { $(xml.responseXML).find("myValue").each(function() { field1 = $(this).attr('attr1'); field2 = $(this).attr('attr2'); alert(field1 + ' ' field2);
I am not sending the exact code that I am running, as the code is rather complicated. If there are syntax errors in the submitted code, do not pay attention, as this is not the cause of my problem. The code works as expected in Firefox, but not in IE or Chrome. In addition, I can verify in Firebug lite that the order in which the code is run should not cause a problem. What I'm trying to do is call the web service, analyze the results and save the necessary information in a global variable for use in later functions, which I can only call after the DOM has finished loading. I run the setUserFields function before loading the document. The function is called and sets the variables, but the variables are only available in the parseXML () scope. Since I declared variables outside of all functions and set the variables inside the parseXML function, I would expect the variables to be set globally. However, only in firefox can I access variables without them undefined. I'm new to the javascript arena, so I may miss the obvious trap. I tried to walk for hours without any luck. Any help would be greatly appreciated.
source share