【问题标题】:Cannot trigger jQuery.ajax() on dynamic anchor generated with PHP无法在 PHP 生成的动态锚点上触发 jQuery.ajax()
【发布时间】:2014-05-10 23:53:49
【问题描述】:

我正在开发的功能有点问题。我在使用数据库查询动态生成的表行列表中有一个锚点<a>。我要做的就是在我的数据库中删除一条调用 php 脚本而不重新加载页面的记录。

这是我的功能:

$(document).on("click",".scollega", function () {
    var id_professionista = $(this).attr('id');
    var id_geocentro = $("#selezione_centri option:selected").val();
    var link_to_trigger = "scollega_prof.php?id_professionista="+id_professionista+"&id_geocentro="+id_geocentro;
    alert(link_to_trigger); 
    //the code above is working fine, I got an alert with corret url to trigger
    e.preventDefault();
    $.ajax({
            async: true,
            cache: false,
            url: link_to_trigger,
            type: 'GET',
            contentType: false,
            processData: false,
            success:function(){
                alert("Record rimosso");
                var string = ('scripts/server_processing.php?id_geocentro='+id_geocentro);
                table.ajax.url(string).load();
                table.reload();    
            },
            error:function (){
                alert("Si è verificato un errore");
            }
    });
});  

PHP 代码:

<?php 
session_start();
session_cache_limiter('nocache');
if(!isset($_SESSION['mail'])){
   header("location:login.php");
}
include("include/connect.php");
$conn=mysql_connect($HOST, $USER, $PASSWORD);
$db_ok=mysql_select_db($DB, $conn);

$query="DELETE FROM centri_operativi WHERE id_professionista='".$_GET['id_professionista']."' AND id_geocentro='".$_GET['id_geocentro']."'";

$ris=mysql_query($query, $conn);

mysql_close($conn);
?>

这似乎是对的,但每次我点击我的按钮时,什么都没有发生。我看不到
也没有错误消息。
希望有人能帮助我。谢谢各位。

贾科莫。

【问题讨论】:

  • 也许你的 php 部分也不能正常工作
  • e in e.preventDefault(); 未定义。也许您打算将它作为事件处理函数的参数?
  • Ops,我完全心不在焉。我纠正了,一切都像魅力一样!谢谢。

标签: javascript php jquery ajax


【解决方案1】:

$.ajax中添加数据属性 Javascript 示例

$.ajax({
            async: true,
            cache: false,
            url: "scollega_prof.php",
            type: 'GET',
            data: {id_professionista: id_professionista, id_geocentro: id_geocentro},
            success:function(){
                alert("success");
            },
            error:function (){
                alert("error");
            }
});

【讨论】:

  • 谢谢。这是一个更好的解决方案:)
猜你喜欢
  • 2014-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-19
  • 2012-06-19
  • 1970-01-01
  • 1970-01-01
  • 2013-02-01
相关资源
最近更新 更多