Javascript PHP:请问如何在删除请求后将用户重定向到通知页面?
我有一个网站,用户可以启动激活请求,付款完成激活,或删除请求(这将让用户返回到通知页面) 启动激活请求和支付工作正常-感谢我在这里得到的帮助 但是,仍然需要解决的困难部分是能够将用户重定向到通知页面,删除查询正在工作,但重定向不起作用 我试过从我在这里看到的类似问题中得到一些帮助,但没有一个对我有用 这是HTML部分,我有删除按钮和要删除的项目id:Javascript PHP:请问如何在删除请求后将用户重定向到通知页面?,javascript,php,Javascript,Php,我有一个网站,用户可以启动激活请求,付款完成激活,或删除请求(这将让用户返回到通知页面) 启动激活请求和支付工作正常-感谢我在这里得到的帮助 但是,仍然需要解决的困难部分是能够将用户重定向到通知页面,删除查询正在工作,但重定向不起作用 我试过从我在这里看到的类似问题中得到一些帮助,但没有一个对我有用 这是HTML部分,我有删除按钮和要删除的项目id: <div class="nk-kycfm-action pt-2"> <input type="
<div class="nk-kycfm-action pt-2">
<input type="hidden" value="23" id="del_ID">
<button class="btn btn-lg btn-danger remove">Delete</button>
</div>
一旦删除查询成功,我只需要能够将用户重定向回bia-package-notification.php。在重定向用户时,您需要提供完整的域信息
header('Location: http://www.mywebsite.com/bia-package-notification.php');
exit();
请查看php头函数的文档: 您应该提供url而不是php文件
<?php
/* You need to make sure that there is no output before this line otherwise you must use output buffering */
header('Location: http://www.example.com/');
exit;
?>
另外,如果($stmt->infected_rows==1),请确保脚本的这一部分通过了检查,并且执行了头部分。这听起来像是ajax完成后,您需要它重定向用户。这可以使用Javascript实现
<script type="text/javascript">
$(".remove").click(function(){
var delVal = document.getElementById("del_ID").value;
if(confirm('Are you sure to delete this Activation request?'))
{
$.ajax({
url: 'bia-deleting-request-one.php',
type: 'GET',
data: {id: delVal},
success: function() {
window.location.href = "bia-package-notification.php";
}
error: function() {
alert("Deletion not successful");
}
});
}
});
</script>
$(“.remove”)。单击(函数(){
var delVal=document.getElementById(“del_ID”).value;
如果(确认('您确定要删除此激活请求吗?'))
{
$.ajax({
url:'bia删除请求一.php',
键入:“GET”,
数据:{id:delVal},
成功:函数(){
window.location.href=“bia package notification.php”;
}
错误:函数(){
警报(“删除不成功”);
}
});
}
});
为什么只有删除行时才需要重定向?也许这就是问题所在?当您发出后台请求时,您不能使用服务器端重定向来重定向前端。您必须使用JavaScript来执行重定向。您的另一个尝试是,通过echo执行重定向“window.location.href=…
不起作用,因为您没有在客户端执行收到的代码。@Justinas请确保我正在重定向已删除他/她的用户record@CBroe如何使用javascript并在客户端执行代码?不,您不需要<代码>标题('Location:bia package notification.php')代码>很好谢谢@Techeatah这对我来说真的很有效,我很感激你。我很高兴:)@Uche很乐意帮忙:)
header('Location: http://www.mywebsite.com/bia-package-notification.php');
exit();
<?php
/* You need to make sure that there is no output before this line otherwise you must use output buffering */
header('Location: http://www.example.com/');
exit;
?>
<script type="text/javascript">
$(".remove").click(function(){
var delVal = document.getElementById("del_ID").value;
if(confirm('Are you sure to delete this Activation request?'))
{
$.ajax({
url: 'bia-deleting-request-one.php',
type: 'GET',
data: {id: delVal},
success: function() {
window.location.href = "bia-package-notification.php";
}
error: function() {
alert("Deletion not successful");
}
});
}
});
</script>