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

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. :)
(definition.html)

<html>
<head>
<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;
     request.send(null);
   }
 
   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;
     }
  http.send(null);
}
</script>
</head>
<body style="background-color:aliceblue;">
<center><h1>Dictionary</h1></center>
<div id="containerword">
<form>
  <input type="text" onkeyup="validate(this.value)" id="word">Dictionary</input>
  </form>
</div>
<form>
  <div id="foo">A reference book containing an alphabetical list of words with information about them.</div>
</form>
</body>
</html>

Where you get it from the actual database..
(definition.php)

<?php
$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'];
}

mysql_close($conn);
?>

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

Tell me how it works!

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.