Javascript 无法在使用PHP生成的动态锚点上触发jQuery.ajax()
我正在开发的一个函数有点问题。我在一个由数据库查询动态生成的表行列表中找到了一个锚点Javascript 无法在使用PHP生成的动态锚点上触发jQuery.ajax(),javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我正在开发的一个函数有点问题。我在一个由数据库查询动态生成的表行列表中找到了一个锚点。我所要做的就是删除数据库中调用php脚本的记录,而无需重新加载页面 以下是我的职能: $(document).on("click",".scollega", function () { var id_professionista = $(this).attr('id'); var id_geocentro = $("#selezione_centri option:selected").val(
。我所要做的就是删除数据库中调用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);
?>
在$.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");
}
});
可能您的php部分在e.preventDefault()中的e
中也无法正常工作代码>未定义。也许你想把它作为事件处理函数的参数?哎呀,我完全是心不在焉。我纠正了,一切都像一个符咒!谢谢,谢谢。这是一个更好的解决方案:)