[英]Opening a page popup on ajax success
I am doing a project and im having problem with window.open. 我正在做一个项目,我在window.open中遇到问题。 The problem is window.open doesnt work in my schema.
问题是window.open在我的架构中不起作用。 i need a help on this,
我对此需要帮助,
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");
}
}
});
}
so i can execute insertData() with no problem.but the problem lies when executin windows.open inside swal(). 所以我可以毫无问题地执行insertData()。但是问题出在swal()的windows.open中执行时。 i dont see any window popup is opening.
我没有看到任何弹出窗口打开。
It's the popup-blocking logic in action that browsers use. 这是浏览器使用的弹出窗口阻止逻辑。 You have to attach window.open directly on onClick event.
您必须直接在onClick事件上附加window.open。
Use something like this: 使用这样的东西:
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");
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.