我正在使用 sweetalert 在 ajax 响应成功时显示一条消息,但它没有正确显示,即没有显示成功图标。
这是我的ajax代码
var formData = $("#enqform").serialize();
jQuery.ajax({
type: 'POST',
url: '<?php echo base_url() ?>tour-package/send-mail',
data: formData,
dataType: 'json',
success: function(data){
if(data.status == 1){
swal({
title: "Thankyou!",
text: "Our excecutives will contact you soon.",
icon: "success",
});
window.setTimeout(function() {
window.location.href = '<?php echo base_url() ?>tour-packages';
}, 100000);
}
else{
swal("Error occured !");
}
}
});
return false;
e.preventDefault();
}
Run Code Online (Sandbox Code Playgroud)
https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.19.2/sweetalert2.min.css
https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.19.2/sweetalert2.min.js
我正在使用这些 css 和 js 来访问 sweetalert。
我想在提交表单时呈现等待时间动画,但我更喜欢使用SweetAlert而不是标准加载图像。
这是基本代码:
$("form").submit(function (e) {
e.preventDefault(); // stops the default action
$("#loader").show(); // shows the loading screen
$.ajax({
url: test.php,
type: "POST"
success: function (returnhtml) {
$("#loader").hide(); // hides loading sccreen in success call back
}
});
});Run Code Online (Sandbox Code Playgroud)
这是 SweetAlert 想要实现的代码:
window.swal({
title: "Checking...",
text: "Please wait",
imageUrl: "images/ajaxloader.gif",
showConfirmButton: false,
allowOutsideClick: false
});
//using setTimeout to simulate ajax request
setTimeout(() => {
window.swal({
title: "Finished!",
showConfirmButton: false,
timer: 1000
});
}, 2000);Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert-dev.js"></script>
<link …Run Code Online (Sandbox Code Playgroud)我正在使用sweetalert2 v7.0.0,如果数量字段为空,我试图显示一个错误。
当我第一次输入金额时,它可以正常工作。
当我第一次尝试将该字段留空时,我收到验证错误。之后,当我输入金额并单击“提交”按钮时,验证错误不会消失。卡住了,第二次没有验证。这是jsfiddle链接。如果您能给我指路,我将不胜感激。我在哪里做错了?
<a href="#" class="refundbutton"><i class="fa fa-undo"></i> Refund</a>
$(".refundbutton").click(function(){
swal({
title: 'Enter Refund Details',
html:'<label for="ipt" class=" control-label"><span class="oval">1</span> Select refund type</label><select class="form-control refund_type"><option value="4"> Credit Card </option> <option value="5"> Cash </option></select>' +
'<label for="ipt" class=" control-label"><span class="oval">2</span> Enter refund amount</label><input type="text" class="form-control nDiscount_fixed" autocomplete="off" style="height: 34px;" value="">',
showCancelButton: true,
confirmButtonText: 'Submit',
preConfirm: function (value) {
return new Promise(function (resolve, reject) {
if ($(".nDiscount_fixed").val() === "") {
swal.showValidationError(
'please enter a refund amount.'
) …Run Code Online (Sandbox Code Playgroud) 我的网站上有代码,使用 SweetAlert2 弹出窗口让用户请求歌曲:
$('#request-song').click(async function() {
const { value: song } = await swal({
title: "Request a Song (please note song request won't be played unless we are live)",
input: 'text',
inputPlaceholder: 'Enter Artist - Song Name',
});
if (song) {
$.post("functions/request.php", {request: song}, function(data) {
console.log(data);
});
swal({type: 'success', title: 'Success!'});
}
});
Run Code Online (Sandbox Code Playgroud)
但是当我添加另一个输入时,它只会读取第二个输入。如何添加另一个输入,以便听众可以在喊话中包含他们的姓名/用户名?
我有一个将数据插入 MySQL 的代码,该代码运行良好,我想将当前的 java 脚本警报替换为 sweetalert2。我浏览了所有论坛但找不到任何东西。谁能帮我?谢谢。
<?php
//session_start();
//include "dbcon.php";
error_reporting(0);
$conn = new PDO('mysql:host=localhost; dbname=fleet','root', 'root');
$department=$_POST['department'];
$employee=$_POST['employee'];
$approver=$_POST['approver'];
$depart_date=$_POST['depart_date'];
$return_date=$_POST['return_date'];
$depart_time=$_POST['depart_time'];
$return_time=$_POST['return_time'];
$depart_place=$_POST['depart_place'];
$arrival_place=$_POST['arrival_place'];
$reason=$_POST['reason'];
$request_timestamp=$_POST['request_timestamp'];
$approver_email = $_POST['approver_email'];
//employee_name = $_POST['employee_name'];
$employee_name = $_POST['employee_name'];
$approver_name = $_POST['approver_name'];
$employee_title = $_POST['employee_title'];
//$no_of_passengers = '';
//$name_of_passengers = '';
$no_of_passengers = $_POST['no_of_passengers'];
$name_of_passengers = $_POST['name_of_passengers'];
//$no_of_passengers2 = $_POST['no_of_passengers2'];
//$name_of_passengers2 = $_POST['name_of_passengers2'];
//$no_of_passengers2 = '';
//$name_of_passengers2 = '';
$sql2='';
//include "mail.php";
// $no_of_passengers2 = $_POST['no_of_passengers2'];
// $name_of_passengers2 = $_POST['name_of_passengers2'];
if (isset($_POST['submit'])) …Run Code Online (Sandbox Code Playgroud) 我试图制作一个 sweetalert,当用户单击删除按钮时,它将触发一个 sweetalert,当用户单击时,Yes, Delete it!它应该发出 axois 请求来删除状态。当用户单击Yes, Delete it!sweetalert 时,它会关闭,但从未发出请求。如果我删除 sweetalert 并仅留下请求,它将删除该记录。
删除按钮
<button @click="destroy(statuses.id)" class="btn btn-danger btn-flat btn-sm"> <i class="fa fa-remove"></i> </button>
Run Code Online (Sandbox Code Playgroud)
删除方法
methods: {
destroy(id) {
swal({
title: "Delete this order status?",
text: "Are you sure? You won't be able to revert this!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
confirmButtonText: "Yes, Delete it!",
}, () => {
del('status-delete/' + id)
})
}
}
Run Code Online (Sandbox Code Playgroud) 来自: https: //github.com/sweetalert2/sweetalert2/issues/226
$(".swal2-confirm").attr('disabled', 'disabled');
Run Code Online (Sandbox Code Playgroud)
工作正常......但经过几次检查后,我如何以编程方式启用它?
我尝试过$(".swal2-confirm").attr('enabled', 'enabled'); ,但行不通。如何以编程方式再次启用它?
谢谢
sweetalert2 ×7
javascript ×5
jquery ×3
ajax ×1
echo ×1
html ×1
laravel ×1
php ×1
sweetalert ×1
vue.js ×1