【问题标题】:send html link variable to jquery ajax php-file将html链接变量发送到jquery ajax php-file
【发布时间】:2009-12-04 02:27:39
【问题描述】:

我想使用 jquery 来检索嵌入在 html 链接中的变量,spo 我可以使用 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 文件。知道怎么做吗?

【问题讨论】:

  • 当然我会先有document.ready=)

标签: php jquery html ajax


【解决方案1】:

试试这个:

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

【讨论】:

  • 不错的解决方案,如果需要发送 url,请使用 event.target.href
猜你喜欢
  • 1970-01-01
  • 2017-03-14
  • 1970-01-01
  • 2016-07-23
  • 2012-12-30
  • 2011-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多