繁体   English   中英

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

[英]Opening a page popup on ajax success

我正在做一个项目,我在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中执行时。 我没有看到任何弹出窗口打开。

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

使用这样的东西:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM