Using $.post for simple ajax test, what am I missing?
Posted
by Cortopasta
on Stack Overflow
See other posts from Stack Overflow
or by Cortopasta
Published on 2010-03-15T21:22:19Z
Indexed on
2010/03/15
21:29 UTC
Read the original article
Hit count: 217
Playing with jquery for the first time, and I'm trying to get a simple AJAX set up working so I can better understand how things work. Unfortunately, I don't know a whole lot. Here's the HTML with the script:
<html>
<head>
<title>AJAX attempt with jQuery</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function ajax(str){
$("document").ready(function(){
$.post("ajaxjquerytest.php",str,function(){
$("p").html(response);
});
});
</script>
</head>
<body>
<input type="text" onchange="ajax(this.value)"></input>
<p>Age?</p>
</body>
</html>
And here is the PHP it's talking to:
<?php
$age = $_POST['age'];
if ($age < 30)
{
echo "Young";
}
else if ($age > 30)
{
echo "Old";
}
else
{
echo "you're 30";
}
?>
© Stack Overflow or respective owner