热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

弹出成功,退出AJAX成功-PopupsuccessandfadeoutonAJAXsuccess

Iwant,onsuccess,showaninitiallyhiddenalert,andthen,fadeitoutafteranamountofseconds

I want, on success, show an initially hidden alert, and then, fade it out after an amount of seconds.

我想,在成功的时候,显示一个最初隐藏的警报,然后在几秒钟后淡出它。

I don't know why I am not getting this right, which seems pretty simple.

我不知道为什么我做的不好,这看起来很简单。

This is my approach, my PHP:

这是我的方法,我的PHP:

Success!

And my Javascript (the AJAX part):

我的Javascript (AJAX部分):

$.ajax({
            type: 'POST',

            url: 'note.php',
            data: { note: note, request_id: request_id, cve: cve, note_id: note_id, status: status,
                    },

            success: function(msg){  
               $("#success-alert").hide();
                $(".add-note").click(function showAlert() {
                $("#success-alert").alert();
                $("#success-alert").fadeTo(2000, 500).slideUp(500, function(){
               $("#success-alert").alert('close');
                });   
            });

            }
        });

The result is that the alert is not initially hidden, since it is hidden when success.

结果是,警报最初并没有隐藏,因为成功时它是隐藏的。

I have also tried with the hide class and remove the $("#success-alert").hide(); part.

我还尝试过隐藏类并删除$(“#success-alert”).hide();部分。

I am starting to think this is impossible to achieve, to do this on AJAX success, and I have come up with this other (but worse, because it is not on success) solution.

我开始认为这是不可能实现的,要在AJAX上实现这一点,我已经提出了另一个解决方案(但更糟糕的是,因为它不成功)。

$(document).ready (function(){
            $("#success-alert").hide();
            $(".add-note").click(function showAlert() {
                $("#success-alert").alert();
                $("#success-alert").fadeTo(2000, 500).slideUp(500, function(){
               $("#success-alert").alert('close');
                });   
            });
 });

The result is that it works only the first click, the second click don the button doesn't work, only if I refresh the page.

结果是,它只在第一次点击时起作用,第二次点击don按钮不起作用,只有当我刷新页面时。

The other solution I have tried, is to divide the code into:

我尝试过的另一个解决方案是将代码分为:

$(document).ready (function(){
            $("#success-alert").hide();

 });
$(".add-note").click(function showAlert() {
                $("#success-alert").alert();
                $("#success-alert").fadeTo(2000, 500).slideUp(500, function(){
               $("#success-alert").alert('close');
                });   
            });

The result is that I that the alert appears for an instant and disappears instantly.

结果是,警报出现了片刻,立即消失。

How can I solve this, apparently easy problem¿? Thank you very much.

我怎么才能解决这个问题呢?非常感谢。

2 个解决方案

#1


2  

HTML

HTML

Success Message

Success Callback

成功回调

$("#success-alert").show();
setTimeout(function() { $("#success-alert").hide(); }, 5000);

#2


1  

Before your ajax request make sure to hide your alert using a css class or jQuery

在ajax请求之前,请确保使用css类或jQuery隐藏警报

$('#sucess-alert').hide();

In order to solve your problem I've been using setTimeout for the delay and jQuery's fadeToggle to hide the element after some time has passed.

为了解决您的问题,我一直在为延迟使用setTimeout和jQuery的fadeToggle在一段时间后隐藏元素。

$.ajax({
    type: 'POST',
    url: 'note.php',
    data: {
        note: note,
        request_id: request_id,
        cve: cve,
        note_id: note_id,
        status: status
    },
    success: function(data){
        var fadeDuration = 500;
        var fadeDelay = 2000;

        var successAlert = $('#sucess-alert');

        successAlert.show();
        setTimeout(function() {
            successAlert.fadeToggle(fadeDuration);
        }, fadeDelay);
    }
});

推荐阅读
  • javascript二叉树基本功能实现
    都是常用的功能。删除是最复杂的。。test ... [详细]
  • jquery定时器调用函数时传参varli$(.firstli:first-child);varindex0;vars$(.firstli);functiongundong(a ... [详细]
  • 一、什么是闭包?有什么作用什么是闭包闭包是定义在一个函数内部的函数,它可以访问父级函数的内部变量。当一个闭包被创建时,会关联一个作用域—— ... [详细]
  • JavaWeb中读取文件资源的路径问题及解决方法
    在JavaWeb开发中,读取文件资源的路径是一个常见的问题。本文介绍了使用绝对路径和相对路径两种方法来解决这个问题,并给出了相应的代码示例。同时,还讨论了使用绝对路径的优缺点,以及如何正确使用相对路径来读取文件。通过本文的学习,读者可以掌握在JavaWeb中正确找到和读取文件资源的方法。 ... [详细]
  • 本文介绍了Java后台Jsonp处理方法及其应用场景。首先解释了Jsonp是一个非官方的协议,它允许在服务器端通过Script tags返回至客户端,并通过javascript callback的形式实现跨域访问。然后介绍了JSON系统开发方法,它是一种面向数据结构的分析和设计方法,以活动为中心,将一连串的活动顺序组合成一个完整的工作进程。接着给出了一个客户端示例代码,使用了jQuery的ajax方法请求一个Jsonp数据。 ... [详细]
  • 前段时间做一个项目,需求是对每个视频添加预览图,这个问题最终选择方案是:用canvas.toDataYRL();来做转换获取视频的一个截图,添加到页面中,达到自动添加预览图的目的。 ... [详细]
  • 工作经验谈之-让百度地图API调用数据库内容 及详解
    这段时间,所在项目中要用到的一个模块,就是让数据库中的内容在百度地图上展现出来,如经纬度。主要实现以下几点功能:1.读取数据库中的经纬度值在百度上标注出来。2.点击标注弹出对应信息。3 ... [详细]
  • Matlab 中的一些小技巧(2)
    1.Ctrl+D打开子程序  在MATLAB的Editor中,将输入光标放到一个子程序名称中间,然后按Ctrl+D可以打开该子函数的m文件。当然这个子程序要在路径列表中(或在当前工作路径中)。实际上 ... [详细]
  • 我正在尝试使用scrapycrallsingle运行完美运行的scrapy蜘蛛,但我无法在python脚本中运行它.主要问题是从不执行SingleBlogSpider.parse方 ... [详细]
  • 前言对于从事技术的人员来说ajax是这好东西,都会使用,而且乐于使用。但对于新手,开发一个ajax实例,还有是难度的,必竟对于他们这是新东西。leo开发一个简单的ajax实例,用的是 ... [详细]
  • 作者一直强调的一个概念叫做oneloopperthread,撇开多线程不谈,本篇博文将学习,怎么将传统的IO复用pollepoll封装到C++类中。1.IO复用复习使用p ... [详细]
  • 个人学习使用:谨慎参考1Client类importcom.thoughtworks.gauge.Step;importcom.thoughtworks.gauge.T ... [详细]
  • Python瓦片图下载、合并、绘图、标记的代码示例
    本文提供了Python瓦片图下载、合并、绘图、标记的代码示例,包括下载代码、多线程下载、图像处理等功能。通过参考geoserver,使用PIL、cv2、numpy、gdal、osr等库实现了瓦片图的下载、合并、绘图和标记功能。代码示例详细介绍了各个功能的实现方法,供读者参考使用。 ... [详细]
  • Spring常用注解(绝对经典),全靠这份Java知识点PDF大全
    本文介绍了Spring常用注解和注入bean的注解,包括@Bean、@Autowired、@Inject等,同时提供了一个Java知识点PDF大全的资源链接。其中详细介绍了ColorFactoryBean的使用,以及@Autowired和@Inject的区别和用法。此外,还提到了@Required属性的配置和使用。 ... [详细]
  • 嵌套函数定义时先判断function_exists防止递归调用外部函数导致两次定义内部函数导致致命错误看一下PHP手册中是如何说的: ... [详细]
author-avatar
够不李先生
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有