views:

80

answers:

1

i want to use jquery to retrieve a variable embedded in a html link, spo i can send it to the php file with jquery ajax. but i dont know how to do this.

this is what i have written:

    <script ...>
        $("a").click(function(){
             $.post("helpers/ajaxcall_country.php", {"HERE I WANT TO SEND THE VARIABLE"}, function(data){
             $("#countryselect").html(data);
            });
        });
    </script>


    while($row = mysqli_fetch_assoc($all_tags))
    {
      echo "<a id='" . $row['id'] . "' href=''>+</a>&nbsp;&nbsp;";
    }

it will be lets say 20 links ... all with different "id". i want to send this "id" value to php-file with ajax. any idea how to do it?

+1  A: 

try this:

<script ...>
    $("a").click(function(event){
         $.post("helpers/ajaxcall_country.php", {id: event.target.id}, function(data){
            $("#countryselect").html(data);
        });
    });
</script>
Janek