2016-04-06 18 views
0

Bir proje yapıyorum ve window.open ile sorun yaşıyorum. Sorun, window.open şemada çalışmıyor. i ajax başarımında bir sayfa açıldı

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"); 
      } 
     } 
    }); 
} 

yüzden Swal içine windows.open sonuç alma sorun yatıyor hiçbir problem.but ile insertData() yürütebileceği, bu konuda bir ihtiyaç(). Pencerede açılan bir pencere açılmıyor.

+0

'yerde swal'. Ayrıca, bu işlevin ne yaptığını bize gösterir misiniz? –

+0

@MatthewHerbst http://t4t5.github.io/sweetalert/ –

+0

@MisterM yardımsever, teşekkürler! –

cevap

1

Bu, tarayıcıların kullandığı açılır pencere engelleyicidir. Window.open'i doğrudan onClick olayına eklemeniz gerekir. Böyle

Kullanım şey: Sen hiç aramıyorsun

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"); 
    } 
}) 
+0

aslında bunların hepsi bir işlev içinde bulunmaktadır dataData() ve tetikleyici

+0

window.open doğrudan tıklama eylemi sırasında kullanmanız gerekir veya büyük olasılıkla tarayıcılar bunu engelleyecektir. Sonra ajax başarısından sonra yerini değiştirebilirsin. –

+0

tamam bunu aklımda tutuyorum ... teşekkür ederim –

İlgili konular