gpt4 book ai didi

javascript - 通过ajax将值传递给另一个脚本

转载 作者:行者123 更新时间:2023-11-28 06:34:40 25 4
gpt4 key购买 nike

下面是一段放置在for循环中的代码

for( some condition will go here )
{
echo "<td>
<a href='event.php?event_id=".$datee2. "&action=Details'>". ($i - $startday + 1) . "</a>
</td>";
}

单击它后,用户将被定向到 event.php 页面,并且 event_id 和 action 参数也会随之前进,

但不是这个我希望通过ajax将event.php页面调用到第一页,为此我尝试了这个

<script>
function chk()
{
$.ajax({
type:"post",
url: "event.php",
data:dataString,
cache:false,
success: function(html)
{
$('#msg').html(html);
}
}) ;
return false;
}
</script>

echo
"<td>
<a onclick='return chk()'>". ($i - $startday + 1) . "</a>
</td>";

但是它不起作用,我也希望你在每次点击时通过ajax将event_id和action参数转发到event.php页面,任何人都可以告诉如何做到这一点

最佳答案

这是你可以做的

<a href="#" class="myclass" data-id="'.$someID.'" data-action="'.$someAction.'">

js 将是

$(".myclass").on("click", function(){
var id = $(this).data("id");
var action = $(this).data("action");

$.ajax({
type : "post",
url : "event.php",
data : {
"id":id,
"action":action
},
cache : false,
success : function(html)
{
$('#msg').html(html);
}
});
});

关于javascript - 通过ajax将值传递给另一个脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34395478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com