> 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

First of all if you send request by POST ($.post) then in PHP you var
will be in $_POST array, if by GET ($.get) in $_GET (there is an
exception, read about "register_globals"),
so in PHP you should use $_POST['namn']

Second of all, your request imho runs well (you can check that with
Firebug (in NET tab)), but you forgot to put callback:

   $.post("test.php",{
         namn: $("#namn").val()}, function(data) { //this is callback
             alert(data); //do something with return data
         });

and thats all! :)

Hope it helps :)

Regards
Michael

Reply via email to