我使用带有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返回值相关推荐

  1. 【Ajax】了解Ajax与jQuery中的Ajax

    一.了解Ajax 什么是Ajax Ajax 的全称是 Asynchronous Javascript And XML(异步 JavaScript 和 XML). 通俗的理解:在网页中利用 XMLHtt ...

  2. SpringMVC中通过@ResponseBody返回对象,Js中调用@ResponseBody返回值,统计剩余评论字数的js,@RequestParam默认值,@PathVariable的用法

    1.SpringMVC中通过@ResponseBody返回对象,作为JQuery中的ajax返回值 package com.kuman.cartoon.controller; import java. ...

  3. python函数内部返回的值_Python中函数的返回值示例浅析

    前言: 前面我们介绍了简单的介绍了函数和函数的参数,今天我们来说一下Python中函数的返回值. 函数的返回值:函数运算的结果,需要进一步的操作时,给一个返回值return用来返回函数的结果,如果没有 ...

  4. python函数返回值_Python中函数的返回值示例浅析

    前言: 前面我们介绍了简单的介绍了函数和函数的参数,今天我们来说一下Python中函数的返回值. 函数的返回值:函数运算的结果,需要进一步的操作时,给一个返回值return用来返回函数的结果,如果没有 ...

  5. JAVA中返回值为字母时_LeetCode#524通过删除字母匹配到字典里最长单词-java中CompareTo方法用法以及Comparator中Compare方法返回值...

    import java.util.Collections; import java.util.Comparator; import java.util.List; /* 524. 通过删除字母匹配到字 ...

  6. 决定c++语言中函数的返回值类型的是,全国2009年10月高等教育自学考试C++程序设计试题及部分参考答案...

    全国2009年10月高等教育自学考试 C++程序设计试题 课程代码:04737 一.单项选择题(本大题共20小题,每小题1分,共20分) 在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码 ...

  7. 如何用mshtml获得Javascript中function的返回值[mshtml]

    marginwidth="0" marginheight="0" src="http://218.16.120.35:65001/PC/Global/ ...

  8. Stackoverflow热门问题(二十二)-如何在Windows cmd中得到程序返回值?

    文章首发及后续更新:https://mwhls.top/2873.html 新的更新内容请到mwhls.top查看. 无图/无目录/格式错误/更多相关请到上方的文章首发页面查看. stackoverf ...

  9. java return返回值_java中关于return返回值的用法详解

    我们输入一个条件时,系统就会对这个条件进行判断,然后给出一个返回时的结论,我们把这个结果看做是返回值.在java里可以使用return语句来进行返回,从字面意思就能很好的理解它的用法了.下面我们就re ...

最新文章

  1. 从民工到CCNA-献给想考认证的朋友
  2. Android Studio导入 jar包的方法
  3. python中join和split使用
  4. android Launcher——ui框架
  5. Windows开启winrm
  6. day17.什么是堆栈
  7. Mac Safari, Chrome 浏览器劫持 SearchSystem Search 恶意插件移除 尝试Brave浏览器
  8. 20145325张梓靖 《网络对抗技术》 Web安全基础实践
  9. 每日一练——回文链表
  10. 龙ol服务器维护补偿boss,龙OL副本BOOS位置攻击属性及掉落物品介绍
  11. win10 解决:无法访问网络地址
  12. Redis(狂神说 )学习使用笔记
  13. 支付宝 福卡 出花花卡 敬业福 的 福图片
  14. 高速试验检测报告依据、结论、监理批复用语
  15. 【郝斌老师数据结构学习笔记 day 6】
  16. oracle统计函数
  17. 【福利】Python抖音小视频无水印下载工具助手exe
  18. 阿里微服务架构的分布式事务GTS
  19. 计算机语言VLOOKUP,“如何查看EXCEL的编程语言“查看excle的代码
  20. 百度招财猫新加入区块链游戏,喜欢数字猫咪的你了解一下

热门文章

  1. 单例模式的创建(饿汉模式懒汉模式)
  2. 百练2075:Tangled in Cables题解
  3. 苹果库克慌了!iPhone XR降价也没人买,原来是华为放大招了
  4. GB/T 28181-2016
  5. 封装 解封装 网线制作
  6. 0xC015000F 正在被停用的激活上下文不是最近激活的”错误解决方法
  7. 关于C语言函数返回数组的问题【转】
  8. Google Play Store无法搜索应用或提示应用不兼容,此类问题该如何定位及分析
  9. Android使用AudioTrack播放WAV音频文件
  10. C语言实验——判断素数(循环结构)