douyiqi9640 2014-05-10 15:14
浏览 99
已采纳

无法在使用PHP生成的动态锚点上触发jQuery.ajax()

I've got a little issue with a function I'm developing. I've got an anchor <a> in a list of table's row generated dynamically with a database query. All I want to do is to remove a record in my database calling a php script without reloading page.

Here my function:

$(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 Code:

<?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);
?>

It seems right, but every time I click my button, nothing happens. I'm not able to see
neither the error message.
Hope someone will help me. Thank you guys.

Giacomo.

  • 写回答

1条回答 默认 最新

  • douyou2048 2014-05-10 15:52
    关注

    Add data property in $.ajax Example in 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");
                }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度