hey everyone,
i am trying to create a web page using Ajax to create a dictionary well simply when you write down a word its definition would show up straight away. the definition would be stored in the file followed by the word.
can anyone recommend me how to start this or show me some examples because i'm currently independently learning Ajax and im finding it quite difficult.
thanks in advance

7 Years
Discussion Span
Last Post by gedas

Here's what you do.
You have a file. Call it 'search.php'. The ajax will get the result from the file (I'm assuming that you know php, and that this is all stored in a database) and will return it. :)
I could write some code for it, I guess. It's not that hard. Give me a few minutes, and I'll edit this post.


Here's what I wrote. :)
The basic code. :)

<title>Test HTML</title>
<script type="text/javascript">
var http = false;

if(navigator.appName == "Microsoft Internet Explorer") {
  http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  http = new XMLHttpRequest();
   function getDefinition() {
     var word = document.getElementById("word").value;
     var url = "definition.php?word=" + escape(word);
     request.open("GET", url, true);
     request.onreadystatechange = updatePage;
   function updatePage() {
     if (request.readyState == 4) {
       /* Get the response from the server */
       var theDefinition = request.responseText;
       /* Update the HTML web form */
       document.getElementById("foo").value = theDefinition;
<body style="background-color:aliceblue;">
<div id="containerword">
  <input type="text" onkeyup="validate(this.value)" id="word">Dictionary</input>
  <div id="foo">A reference book containing an alphabetical list of words with information about them.</div>

Where you get it from the actual database..

$conn = @mysql_connect("DB_HOST", "DB_USERNAME", "DB_PASSWORD");
if (!$conn)
  die("Error connecting to MySQL: " . mysql_error());

if (!mysql_select_db("DB_NAME", $conn))
  die("Error selecting database: " . mysql_error());

$word = preg_replace("/[\. \(\)\-]/", "", $_REQUEST['word']);
$select = 'SELECT *';
$from   = '  FROM table_name';
$where  = ' WHERE word = \'' . $word . '\'';
$queryResult = @mysql_query($select . $from . $where);
if (!$queryResult)
  die('Error retrieving customer from the database.');

$num = mysql_num_rows($queryResult);
if ($num == 0) {
  $queryResult = @mysql_query($select . $from);

while ($row = mysql_fetch_array($queryResult)) {
  echo $row['definition'];


Some of the code is thanks to here: http://www.headfirstlabs.com/books/hrajax/

Tell me how it works!

Edited by Arianna: n/a


thanks a lot for this i will try upload it in the database and i will let you know weather or not it is working .
thank a lot really appreciate it

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.