Possible Duplicate:
jQuery: Return data after ajax call success
So I'm calling a Sharepoint service and trying to return some values for use elsewhere and I'm trying to declare a window variable to do so. Seems simple but the window variables are undefined outside the responseXML functions.
userName = "";
var soapEnv =
"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:tns='http://schemas.microsoft.com/sharepoint/soap/'> \
    <soap:Body> \
        <GetUserProfileByName xmlns='http://microsoft.com/webservices/SharePointPortalServer/UserProfileService'> \
            <AccountName></AccountName> \
        </GetUserProfileByName> \
    </soap:Body> \
</soap:Envelope>";
$.ajax({
    url: "/_vti_bin/userprofileservice.asmx",
    type: "POST",
    dataType: "xml",
    data: soapEnv,
    complete: processResult,
    contentType: "text/xml; charset='utf-8'"    
});
function processResult(xData, status) {
    $(xData.responseXML).find("PropertyData > Name:contains('FirstName')").each(function() {
        window.FirstName = $(this).parent().find("Values").text();
    });
    $(xData.responseXML).find("PropertyData > Name:contains('LastName')").each(function() {
        window.LastName = $(this).parent().find("Values").text();
    });
}
    userName += window.FirstName;
    userName += " " + window.LastName;
    console.log(userName);
 
     
     
    