Change two different elements with one ajax call

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bugboy
    New Member
    • Sep 2007
    • 160

    Change two different elements with one ajax call

    This ajax is called from an onclick in a form element. I want to use one call to change 2 different elements. Is there a way to change the contents of another element at the same time, not just list_id? I'm having a tough time getting my head around js. and have tried lots of different things with no luck :(

    Thanks!

    Code:
    function save_edit_row(list, value)
    	{ 
    	xmlHttp=GetXmlHttpObject()
    	if (xmlHttp==null)
    		 {
    		 alert ("Browser does not support HTTP Request")
    		 return
    		 }
    	var url="save_edit_row.php"
    	url=url+"?list="+list
    	url=url+"&row_num="+row_num
    	url=url+"&value="+value
    	url=url+"&rand="+Math.random()
    	xmlHttp.onreadystatechange=list_stateChange
    	xmlHttp.open("GET",url,true)
    	xmlHttp.send(null)
    	}
    
    
    
    
    function list_stateChange()
    	{ 
    	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    		 { 
    		 document.getElementById('list_id').innerHTML=xmlHttp.responseText 
    		 } 
    	}
    
    
    
    function GetXmlHttpObject()
    	{
    	var xmlHttp=null;
    	try
    		 {
    		 // Firefox, Opera 8.0+, Safari
    		 xmlHttp=new XMLHttpRequest();
    		 }
    	catch (e)
    		 {
    		 //Internet Explorer
    		 try
    			  {
    			  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    			  }
    		 catch (e)
    			 {
    			 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    			 }
    		 }
    		 return xmlHttp;
    	}
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Yes, you can. Split the response text and set one to one element and the other to the second element, e.g. if you return "one|two", you can use .split("|") to get an array where arr[0] would contain "one" and arr[1] "two".

    Comment

    Working...