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
https://forums.phpfreaks.com/topic/118610-learning-ajax/
Share on other sites

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.