Jump to content

learning ajax


alin19

Recommended Posts

i'm trying to learn a little ajax from a book, and i have a write a code exactly like it says in my book; but the result isn't what i need,

there is a javascript function that is not executed. can you take a look around

<html>
<head>

<script language="javascript" type="text/javascript">
<!--
  var cerere;
function obtineNumar(prieten){
if (prieten=="")
return;
var url="numere.php?nume="+prieten;
var nodNumar = document.getElementById('numar');

nodNumar.setAttribute('value','Caut..');
}

function trateazaCererea() {
if (cerere.readyState==4) {
if (cerere.status==200) {

  raspuns = cerere.responseText;
  var nodNumar = document.getElementById('numar');
  nodNumar.setAttribute('value',raspuns);
  }
  else
  {
  alert ("datele nu pot ficautate" +cerere.statusText);
  }
  }
  }
  -->
  </script>

</head>

<body>
<form name="numere">
<table>
  <tr>
  <td>Prieten</td>
  <td><input type="text" size="20" maxlength="30" id="prieten" name="prieten" onchange="obtineNumar(this.value);" /></td></tr>
  
  <tr><td>Numar de tel</td>
  <td><input type="text" size="20" id="numar" name="numar" />
  </td></tr>
  </table>
  </form>
  
</body>
</html>
  

<?php
$conexiune=mysql_connect("localhost","root","tractor") or die("conexiunea nu a putut fi realizata");
mysql_select_db("xml",$conexiune) or die ("accesul la baza de date nu a putut fi realizat");
$nume=$_GET['nume'];
$interogare="select `numarr` from `numere` where `nume`='$nume'";
$rezultat=mysql_query($interogare);
if (mysql_num_rows($rezultat) !=1)
echo "nu exista";
else {
$rez=mysql_fetch_row($rezultat);
echo $rez[0];
}
?>

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.