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

 

 

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.