【问题标题】:edit link with GET ajax call not working使用 GET ajax 调用编辑链接不起作用
【发布时间】:2013-05-06 20:58:09
【问题描述】:

我有多个链接列表..

echo '<td><a href="edit.php?pldid=' . mysql_result($query12, $i, 'pld_id') . '" id="editbt">Edit</a></td>';

我是用ajax点击这个的时候用的

 $("#editbt").click(function(event) {
    event.preventDefault();

     $.ajax({
            type: "GET",
            url: this.href,
            cache:false,
            success: function(response){
            alert(response);

            }
     });

});

我的php文件

<?php
include('connect.php');

 if (isset($_GET['pldid'])&& $_GET['pldid'])
 {
 echo $_GET['pldid'];


 }
?>

所以当我点击链接时,我没有收到警报响应,但我被定向到页面本身。

所以当我点击一个链接说 edit.php?pldid=1234 时,我被定向到这个 url edit.php?pldid=1234 并打印了 pldid。

所以 isset($_GET['pldid'])&& $_GET['pldid'] 成立,但没有 ajax 调用..希望我很清楚.. 谢谢..

【问题讨论】:

  • 所有链接都具有相同的id=editbt 吗? ID 必须是唯一的。您应该使用类而不是 ID。

标签: jquery ajax


【解决方案1】:

将您的 PHP 更改为:

echo '<td><a href="edit.php?pldid=' . mysql_result($query12, $i, 'pld_id') . '" class="editbt">Edit</a></td>';

我将id= 更改为class= 以防止重复ID。

把JS改成:

 $(".editbt").click(function(event) {
    event.preventDefault();

     $.ajax({
            type: "GET",
            url: this.href,
            cache:false,
            success: function(response){
            alert(response);

            }
     });

});

我将 $("#editbt") 更改为 $(".editbt") 以按类而不是 ID 进行选择。

【讨论】:

    猜你喜欢
    • 2018-07-05
    • 2010-09-30
    • 1970-01-01
    • 2016-10-24
    • 2011-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-26
    相关资源
    最近更新 更多