sweetalert 2.0 ajax,处理SweetAlert2中的AJAX返回值
我使用带有AJAX请求的SweetAlert2 Popup。一旦用户点击提交,我执行请求。 在PHP文件中,我对提交的数据进行了一些验证,根据结果,我想在SweetAlert2中为用户提供反馈作为信息。处理SweetAlert2中的AJAX返回值
这是我SweetAlert2代码:
$('#sweet-ajax').click(function() {
swal({
title: "Sure?",
text: "Clicking on validated sends the data to our tool.",
type: "warning",
showCancelButton: true,
closeOnConfirm: false,
confirmButtonText: "Yes, submit!",
cancelButtonText: "Cancel",
showLoaderOnConfirm: true,
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger m-l-10',
preConfirm: function(givenData){
return new Promise(function(resolve, reject) {
setTimeout(function(){
//if statment only for test purposes filled with 2==1
if(2 == 1){
swal("Oops", "Sorry something strange happend!", "error")
}else{
resolve()
}
}, 2000)
})
},
allowOutsideClick: false
}).then(function(givenData){
$.ajax({
type: "post",
url: "/assets/php/checkTool.php",
data: {registration: "success", amount: ammountInput, email: "[email protected]"},
})
swal({
//only if the response from the AJAX is correct - but how?
type: 'success',
title: 'Correct!',
html: 'All safe! Here is the answer from the tool: ' //need to get the return value of the AJAX request and append it here
})
}, function(dismiss) {
if (dismiss === 'cancel') {
swal(
'Cancelled',
'The action have been cancelled by the user :-)',
'error'
)
}
})
});
而且checkTool.php文件:
$registration = $_POST['registration'];
$ammountInput= $_POST['ammount'];
$email= $_POST['email'];
//only some demo things here. Implement it after the SweetAlert2 stuff works properly
if ($registration == "success"){
return response(json_encode(array("abc"=>'Success')));
}else{
return response(json_encode(array("abc"=>'Error')));
}
?>
我怎么能现在确定的是什么从SweetAlert2的JavaScript代码AJAX请求的响应?
是否可以处理SweetAlert2中的AJAX响应?
2017-07-29
Fabian
sweetalert 2.0 ajax,处理SweetAlert2中的AJAX返回值相关推荐
- 【Ajax】了解Ajax与jQuery中的Ajax
一.了解Ajax 什么是Ajax Ajax 的全称是 Asynchronous Javascript And XML(异步 JavaScript 和 XML). 通俗的理解:在网页中利用 XMLHtt ...
- SpringMVC中通过@ResponseBody返回对象,Js中调用@ResponseBody返回值,统计剩余评论字数的js,@RequestParam默认值,@PathVariable的用法
1.SpringMVC中通过@ResponseBody返回对象,作为JQuery中的ajax返回值 package com.kuman.cartoon.controller; import java. ...
- python函数内部返回的值_Python中函数的返回值示例浅析
前言: 前面我们介绍了简单的介绍了函数和函数的参数,今天我们来说一下Python中函数的返回值. 函数的返回值:函数运算的结果,需要进一步的操作时,给一个返回值return用来返回函数的结果,如果没有 ...
- python函数返回值_Python中函数的返回值示例浅析
前言: 前面我们介绍了简单的介绍了函数和函数的参数,今天我们来说一下Python中函数的返回值. 函数的返回值:函数运算的结果,需要进一步的操作时,给一个返回值return用来返回函数的结果,如果没有 ...
- JAVA中返回值为字母时_LeetCode#524通过删除字母匹配到字典里最长单词-java中CompareTo方法用法以及Comparator中Compare方法返回值...
import java.util.Collections; import java.util.Comparator; import java.util.List; /* 524. 通过删除字母匹配到字 ...
- 决定c++语言中函数的返回值类型的是,全国2009年10月高等教育自学考试C++程序设计试题及部分参考答案...
全国2009年10月高等教育自学考试 C++程序设计试题 课程代码:04737 一.单项选择题(本大题共20小题,每小题1分,共20分) 在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码 ...
- 如何用mshtml获得Javascript中function的返回值[mshtml]
marginwidth="0" marginheight="0" src="http://218.16.120.35:65001/PC/Global/ ...
- Stackoverflow热门问题(二十二)-如何在Windows cmd中得到程序返回值?
文章首发及后续更新:https://mwhls.top/2873.html 新的更新内容请到mwhls.top查看. 无图/无目录/格式错误/更多相关请到上方的文章首发页面查看. stackoverf ...
- java return返回值_java中关于return返回值的用法详解
我们输入一个条件时,系统就会对这个条件进行判断,然后给出一个返回时的结论,我们把这个结果看做是返回值.在java里可以使用return语句来进行返回,从字面意思就能很好的理解它的用法了.下面我们就re ...
最新文章
- 从民工到CCNA-献给想考认证的朋友
- Android Studio导入 jar包的方法
- python中join和split使用
- android Launcher——ui框架
- Windows开启winrm
- day17.什么是堆栈
- Mac Safari, Chrome 浏览器劫持 SearchSystem Search 恶意插件移除 尝试Brave浏览器
- 20145325张梓靖 《网络对抗技术》 Web安全基础实践
- 每日一练——回文链表
- 龙ol服务器维护补偿boss,龙OL副本BOOS位置攻击属性及掉落物品介绍
- win10 解决:无法访问网络地址
- Redis(狂神说 )学习使用笔记
- 支付宝 福卡 出花花卡 敬业福 的 福图片
- 高速试验检测报告依据、结论、监理批复用语
- 【郝斌老师数据结构学习笔记 day 6】
- oracle统计函数
- 【福利】Python抖音小视频无水印下载工具助手exe
- 阿里微服务架构的分布式事务GTS
- 计算机语言VLOOKUP,“如何查看EXCEL的编程语言“查看excle的代码
- 百度招财猫新加入区块链游戏,喜欢数字猫咪的你了解一下