window.location.href无法与sweetalert一起使用

我正在使用html和php创建表单,提交表单后,我想用sweetalert显示成功消息,并希望将窗口定位到另一个页面。我尝试了以下代码,但没有用。请告诉我我要去哪里了


echo '<script type="text/javascript">';

echo 'setTimeout(function () {';

echo 'swal("Success!","Your complaint has been successfully registered.\n Your Customer Complaint No. is\n  "+"'.$complainno.'","success")

    .then( function(val) {  if (result.value) {

        window.location = "/cashier.php";

    }';             

echo '});';

echo '}, 200);  </script>';


冉冉说
浏览 227回答 1
1回答

慕尼黑8549860

这是解决方案:echo '<script>&nbsp; &nbsp; &nbsp; &nbsp; setTimeout(function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; swal({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title: "Success!",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text: "Your complaint has been successfully registered.Your Customer Complaint No. is"+$complainno,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: "success"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.location.href = "cashier.php"; // window.location also can be used&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; }, 1000);</script>';
打开App,查看更多内容
随时随地看视频慕课网APP