成功调用AJAX后,Toast Growl不会出现
Toastr Growl is not showing up after a successful AJAX call
通过我的JavaScript代码,我可以获得错误URL的警报,但当成功POST时,我可以通过alert
调用显示response.id
,但不使用我用于错误URL逻辑的烤面包机咆哮。我是不是错过了什么?
<link href="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.css" rel="stylesheet"/>
<script src="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.js"></script>
<script type="text/javascript">
$(function () {
$('#submit').click(function () {
var txt = $('#url').val();
var re = /(http(s)?:'')?(['w-]+'.)+['w-]+[.com|.in|.org]+('['?%&=]*)?/
if (!re.test(txt)) {
toastr.options = {
"closeButton": false,
"debug": false,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-bottom-center",
"preventDuplicates": false,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
};
toastr["error"]("Invalid URL!");
$('#url').val('');
return false;
}
$.ajax({
url: "{{ url_for('api.start_status') }}",
type: 'POST',
contentType: "application/json",
dataType: 'json',
data: JSON.stringify({"url": txt}),
success: function (response) {
var meme = response.id;
toastr(meme);
}
});
});
});
</script>
UPDATE#1:正如建议的那样,这是现在的代码,它仍然显示出相同的行为。确认它在SAFARI中也不起作用,所以至少有两个浏览器显示了相同的问题。
<link href="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.css" rel="stylesheet"/>
<script src="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.js"></script>
<script type="text/javascript">
$(function () {
toastr.options = {
"closeButton": false,
"debug": true,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-bottom-center",
"preventDuplicates": false,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
};
$('#submit').click(function () {
var txt = $('#url').val();
var re = /(http(s)?:'')?(['w-]+'.)+['w-]+[.com|.in|.org]+('['?%&=]*)?/
if (!re.test(txt)) {
toastr["error"]("Invalid URL!");
$('#url').val('');
return false;
}
$.ajax({
url: "{{ url_for('api.start_status') }}",
type: 'POST',
contentType: "application/json",
dataType: 'json',
data: JSON.stringify({"url": txt}),
success: function (response) {
toastr.success("Invalid URL 2!");
var meme = response.id;
{# alert(meme);#}
}
});
});
});
</script>
因此,无论是否存在格式错误的url或成功的ajax调用,您都希望显示相同的toast。
如果我理解正确,那么当我查看您的代码时,您似乎只在regex.test不成功的情况下才放入tover.options
为了测试,我会将选项移到if(!re.test…)之外?
相关文章:
- 如何在Sencha Touch应用程序中实现自定义Toast
- Toast通知未显示在右下角
- 如果我们在5秒后有一个隐藏间隔,则无法获取Growl消息
- 成功调用AJAX后,Toast Growl不会出现
- Angular Toast无法在打字脚本中工作
- 可以'我不想用BlackBerry Webworks 2来展示Toast
- Toastr JS无限期地保持Toast可见
- 如何将 Toast 消息从 SFB Web SDK 发送到 UCMA 机器人
- Rails 4-Toast通知而不是flash通知
- 在Toast中显示错误和异常,或使用MVC4和实体框架的类似方法
- Angular Toast在我的服务中不起作用
- 使用$mdToast的角度材料设计,toast不会在我的网站上显示
- 具体化toast对话框的更改位置
- 只运行函数一次(显示toast like message) javascript/jquery
- ASP中的Toast通知.Net MVC 4
- 在文档加载时触发materialize.css toast
- ASP中的Toast通知.NET MVC