Q:

Call PHP Function by Ajax

I'm new for Web sites.I have a text box in my page and what i need is when onBlur that text box, call a php method that include sql query.I found something like on the web, but still does net work it.Am i doing wrong?
<?php
if(isset($_POST['Greet']))
   {
      echo $_POST['Greet'];
  }
?>
<html>
<body>
<script type="text/javascript">

function sayHi()
{
     var value = $.ajax({
        type: "POST",
         url: "page.php",
        data: "Greet="+$("#Greeting").val(),
        async: false
        }).responseText;
}

</script>

<input type="text" name="Greeting" id="Greeting" onblur="sayHi()">

</body>
</html>

A:

exit your php for usage in same script, ajax will return entire html.
<?php
    if(isset($_POST['Greet']))
    {
        echo $_POST['Greet'];
        die;
    }
?>

value will have your response alert(value)
later edit:
<?php
    if(isset($_POST['Greet']))
    {
        echo $_POST['Greet'];
        die;
    }
?><html>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript">
function sayHi()
{
    var value = $.ajax({
        type: "POST",
        url: "index.php",
        data: "Greet="+$("#Greeting").val(),
        async: false
    }).responseText;
    $('#result').html(value);
}

</script>
<span id="result"></span>
<input type="text" name="Greeting" id="Greeting" onblur="sayHi()">
</body>
</html>

