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");
                }
    });
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题