开发者

send html link variable to jquery ajax php-file

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(functio开发者_运维问答n(){
             $.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?


try this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜