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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.