Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 91
  • Last Modified:

returning the XML result to a returning function

When I call compexists and alert the response text it displays it correctly, however it displays "undefined" in the validate_transfer function.  I'm not sure what I'm doing wrong here.  I'm using IE 7
function validate_transfer(formname,dialid)
{
	var dupname = compexists(formname.name.value,dialid);
	alert(dupname);
}
 
function compexists(compname,dial_id)
{
    var xmlHttp = getXMLHttp();
    xmlHttp.onreadystatechange = function()
      {
         if(xmlHttp.readyState == 4)
             {
                 alert(xmlHttp.responseText);
                 return xmlHttp.responseText;				
             }
      }
xmlHttp.open("GET", "compexists.php?compname="+compname+"&dialplan_id="+dial_id, true); 
xmlHttp.send(null);	
}

Open in new window

0
ddsexperts
Asked:
ddsexperts
1 Solution
 
wassa_rCommented:
The function compexists doesn't actually return anything. The function onreadystatechange does, see the difference? You'll have to change the onreadystatechange function to actually call part 2 of your validate_transfer();

You'll do something similar to:

validate_transfer(formname, dialid);

change the readystatechange function to

 if(xmlHttp.readyState == 4)
             {
                 
                 valid_transfer2(compname,dial_id,xmlHttp.responsetext);
                                         
             }

then do whatever you want in part 2 with the response.
0
 
cyberhiteshCommented:
Ajax call is asynchronous, so it goes into background and control gets transferred to the alert() which shows undefined because it does not contains any data.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now