Hi Oscar from Sweden,

works loke a charm for me (using PHPs superglobal $_POST), it seems as if you just forgot to add a callbackfunctionthat is going to handle the servers response.

$( document ).ready( function () {
   $( "a#go" ).click(function () {
$.post("test.php", { namn: $( "#namn" ).val() }, function ( serverAnswer ) {
           alert( serverAnswer );
       });
       return false;
   });
});

-- Marc


Oscar from Sweden schrieb:
Hello!
I'm trying to learn jQuery so I can use ajax much easier than writing
ordinary javascripts. But it isn't working for me. Tried soo many
different (and Very easy) things and they won't work. Can someone
explain what I am doing wrong?

This is just a little testpage.
custom.js:
----------------------------
$(document).ready(function() {
        $("a#go").click(function(){
                 $.post("test.php",{
                           namn: $("#namn").val()                        (How 
is this
variable set? to $_POST['namn'] or $namn?)
                         });
        return false;
        });

});
-----------------------------
test.php:

<?
echo "Hello,";
echo $namn."!";     (have tried $_POST['namn'] too)
?>
---------------------------
index.php file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="jquery.js" type="text/javascript"></script>
<script src="custom.js" type="text/javascript"></script>
</head>

<body>
 <p>Hej</p>
 </div>
 <input type="text" name="namn" id="namn" />
<p><a href="#" id="go">GO!</a> </p>
</body>
</html>

-----------------------


I would really appreciate if you helped me understand this. I have
read soo many tutorials on the net but it won't work anyway...
Best Regards /Oscar


Reply via email to