Jump to content

xml response text into a variable


husslela03

Recommended Posts

How do I place an xmlhttp.responseText into a variable.

 

where it is set up now is it in

document.getElementById('word').innerHTML=xmlhttp.responseText

 

and i would like to place it in a variable called

var word, and then be able to do things to it.

 

I'm implementing a game where a user guesses letters.

 

 

Link to comment
https://forums.phpfreaks.com/topic/198583-xml-response-text-into-a-variable/
Share on other sites

<?php

echo 'Welcome to Lingo';



?>

<html>
<head>
</head>
<body>
<script type="text/javascript">
var xmlhttp;
var gameWord;
function myfunction()
{
   //variable to hold the word from the server
  if(window.XMLHttpRequest)
  {
    xmlhttp=new XMLHttpRequest();
  }
  else 
  {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    
  }
  
  xmlhttp.onreadystatechange=function(var gameWord)
  {
      if(xmlhttp.readyState==4)
      {
        document.getElementById('word').innerHTML=xmlhttp.responseText;
        
      }
  
  } 

  xmlhttp.open("POST", "get_word.php", true);
  xmlhttp.send(null);
}
  document.write(gameWord);
  </script>
  <form name="myLingo">
  
  
  <input type="button" value="New Word" onclick="myfunction()" />
  <div id="word">
  
  </div>
  
  </form>
<center>
LINGO
</center>
</body>
</html>

 

what i would really like to do is have a button that gets the word from the dictionary file that i have set up with php and mySQL, then when the word first displays, I want to show blanks first,

however if I can't get it in a variable to manipulate it, i can do the rest...

 

 

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.