簡體   English   中英

發送html鏈接變量到jQuery ajax php文件

[英]send html link variable to jquery ajax php-file

我想使用jquery檢索嵌入在html鏈接中的變量,所以我可以使用jquery ajax將其發送到php文件。 但是我不知道該怎么做。

這是我寫的:

    <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;";
    }

可以說20個鏈接...都帶有不同的“ id”。 我想使用ajax將該“ id”值發送到php文件。 知道怎么做嗎?

嘗試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM