Jump to content

Need help grabbing data from mySQL database


husslela03

Recommended Posts

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.

I recommend JQuery (much easier  :D )

 

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.