Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: ajax probelm

  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts

    ajax probelm

    Hi all,
    I am using ajax to retreive the content of an xml file on my server.
    I am using the xmlhttp.responseXML.documentElement to validate that the data is correct.
    The problem starts when I want to copy this data into a different variable and to access it later.

    I defined a global variable, and in the response function (which is called after the ajax was served) I am duplicating this node into a different one.

    the problem is that when I try later to access this variable from functions within the same file it allways null.

    why is it happenning? is it a scope issue or something else?

    Code:
    var xml_config_dom;
    
    function loadXMLDoc(url)
    {
    	xmlhttp=null;
    	if (window.XMLHttpRequest)
    	{// code for IE7+, Firefox, Chrome, Opera, Safari
    		xmlhttp=new XMLHttpRequest();
    	}
    	else
    	{// code for IE5, IE6
    		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
    	
    	xmlhttp.onreadystatechange=onResponse;
    	xmlhttp.open("GET",url,true);
    	xmlhttp.send(null);
    	
    	
    }
    
    function onResponse()
    {
    	
    	if(xmlhttp.readyState!=4) return;
    	if(xmlhttp.status!=200)
    	{
    		alert("Problem retrieving XML data");
    		return;
    	}
    		xml_config_dom=xmlhttp.responseXML.documentElement.cloneNode(true)
    	
        
    }

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    Can you post your entire setup, or a link to it?

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    How's your cloned XML node looks like? Is it a valid XHTML node as well?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    New Coder
    Join Date
    Dec 2009
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by gusblake View Post
    Can you post your entire setup, or a link to it?
    problem solved.
    I was doing redirection using the window.locatio.href which I undersatnd reload the page and delete all tha varaible.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •