0

I want to know if it is possible to return the xmlhttp.responseText value from an AJAX function to the function that originally called the AJAX function

 function ajaxfunc(adiv,url,parameter){
        if(window.XMLHttpRequest){
            xmlhttp = new XMLHttpRequest();
        }else{
            xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
        }



         xmlhttp.onreadystatechange = function(){
            if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
               responseText_data = xmlhttp.responseText;

            //how to return  responseText_data to myfunc();

            }
        }

        parameters = parameter;
        xmlhttp.open('POST',url,true ); 
        xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
        xmlhttp.send(parameters);


    }

    function myfunc(){
        url       = 'insidefunc.php';
        adiv      = "";
        parameter = 'selected='+'selected';
        ajaxfunc(adiv,url,parameter);


        //alert(responseText_data);
    }
  • Why have you added the tag php? I don't see any php in your post – la3roug Mar 22 '18 at 07:36
  • No. But you can do, what the calling function would have done if it had had the answer. – Holger Mar 22 '18 at 07:40
  • 4
    Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – CBroe Mar 22 '18 at 07:42

0 Answers0