Hey. i hav two page. suppose page.php & page_ajax.php in page.php there are some <input /> form field. & in page_ajax.php there are some JS variable declared (<script....>var xtitle = 'blah blkah'</script>) i want page.php to get those variable from page_ajax.php & put them into those input form's value i tried this...no luck var xmlHttp function getInfo() { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } document.getElementById("getInfoButton").disabled = true; document.getElementById("getInfoButton").value = 'Loading...'; var url="./vbv/page_ajax.php"; xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function stateChanged() { if (xmlHttp.readyState==4) { document.getElementById("title").value = xtitle; document.getElementById("tags").value = xtags; document.getElementById("desc").value = xdesc; document.getElementById("getInfoButton").disabled = false; } } function GetXmlHttpObject() { var xmlHttp=null; try { xmlHttp=new XMLHttpRequest(); } catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } Code (markup): xtitle, xtags, xdesc are the variables already declared in page_ajax.php i tried to grab info by clicking a button (id=getInfoButton & onclick=getInfo() )
You simply need to make page_ajax.php ouput the values of those variables: e.g (page_ajax.php): <script> document.write(xtitle + "," + xtags + "," + xdesc); </script> Code (markup): page.php: var rText = xmlHttp.responseText.split(","); //splits the response by comma(,) and stores each result in an array document.getElementById("title").value = rText[0]; //retrieves first result document.getElementById("tags").value = rText[1]; //second document.getElementById("desc").value = rText[2]; //third Code (markup): If this is not sufficient then you can output xml (from page-ajax.php) and then read the xml(from page.php)... whatever suits your needs.