【发布时间】:2022-01-21 14:21:40
【问题描述】:
我正在尝试使用 Ajax 通过获取请求将数据从超链接传递到页面
最初我可以在没有 Ajax 的情况下直接执行此操作,如下所示
<a id="link" href="page.php?id=12&pid=12" >pass data</a>
我在 php 中捕捉到下面
<?php $_GET['id'] ?>
<?php $_GET['pid']?>
现在我想使用 Ajax 来执行此操作,因此页面不需要加载
我正在尝试以下
<a class="choice" id="link" href="page.php?id=12&pid=12" >pass data</a>
$(document).ready(function() {
$(".choice").click(function(e) {
e.preventDefault();
$.ajax( {
<!--insert.php calls the PHP file-->
url: "votes.php",
method: "get",
dataType: 'html',
success: function(strMessage) {
$("#vote").html(strMessage);
}
});
});
});
但我无法让它工作。我需要有关使用 Ajax 将数据正确实现发送到我的 php 文件的帮助
【问题讨论】: