husslela03 Posted December 7, 2009 Share Posted December 7, 2009 Hello, Basically i have a .js script and a .php script. The .php script grabs a random word from a table of words that i have in a mySQL database. My problem is using the XMLHTTPRequest to put that word into a variable so I can do something with it. I also want to obtain this word by clicking a button. Any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/184318-need-help-grabbing-data-from-mysql-database/ Share on other sites More sharing options...
BenInBlack Posted December 11, 2009 Share Posted December 11, 2009 I recommend JQuery (much easier ) but you need to return xml here is a sample using the old manual mode <script> var xhttp=false; var isIE=false; function makeAjaxCall(data) { if (document.all) { isIE=true;} if (isIE) { if (window.XMLHttpRequest) { // If IE7, Mozilla, Safari, etc: Use native object xhttp = new XMLHttpRequest() } else { if (window.ActiveXObject) { // ...otherwise, use the ActiveX control for IE5.x and IE6 xhttp = new ActiveXObject("Msxml2.XMLHTTP"); } } } else { xhttp = new XMLHttpRequest(); } // set the event handler xhttp.onreadystatechange = ajaxReturn; // prep the call, http method=POST, true=asynchronous call var rankArgs = 'function='+data; xhttp.open("POST", "http://www.domain.com/ws/ws_webservicename.php", true); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // send the call with args xhttp.send(rankArgs); } function ajaxReturn() { if (xhttp.readyState==4) { //responseXML contains an XMLDOM object var x = xhttp.responseXML.getElementsByTagName("root"); var nodes = x[0].getElementsByTagName("test")[0]; if (nodes.childNodes[0]) { var test = nodes.childNodes[0].nodeValue; var rawr = x[0].getElementsByTagName("rawr")[0]; } } </script> Link to comment https://forums.phpfreaks.com/topic/184318-need-help-grabbing-data-from-mysql-database/#findComment-975166 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.