gpt4 book ai didi

javascript - ajax 成功时打开页面弹出窗口

转载 作者:行者123 更新时间:2023-11-29 11:36:49 24 4
gpt4 key购买 nike

我正在做一个项目,但我遇到了 window.open 问题。问题是 window.open 在我的架构中不起作用。我需要这方面的帮助,

swal({
title: "Submit Data ?",
text: "Process only if you are sure",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, Submit!",
cancelButtonText: "No, Cancel!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm){
if (isConfirm) {
insertData();
swal("SUCCESS", "Data Has Been Submitted", "success");
window.open("http://188.109.156.21/execution.php?str=james");
} else {
swal("CANCELLED", "", "error");
}
});

function insertData(){
$.ajax({
type: 'POST',
url: "../../../html/main/divpages/submit_data.php",
data: sentReq,
dataType: 'JSON',
success: function (response, textStatus, jqXHR) {
if (response.indexOf("GAGAL") == -1) {
window.location.href = "main.php";
} else {
alert("GAGAL INSERT");
}
}
});
}

所以我可以毫无问题地执行insertData()。但是问题出在swal()内部执行windows.open时。我没有看到任何弹出窗口打开。

最佳答案

这是浏览器使用的弹出窗口阻止逻辑。您必须将 window.open 直接附加到 onClick 事件上。

使用这样的东西:

var checkSuccess = false;

$('#button').on("click", function(){
$.ajax({
type: 'POST',
url: "your url",
async:false,
success: function(){
checkSuccess = true;
//YOUR LOGIC
}
});
if(checkSuccess){
window.open("http://188.109.156.21/execution.php?str=james");
}
})

关于javascript - ajax 成功时打开页面弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36443929/

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