jquery - 在 AJAX 请求中使用 jQuery 淡入淡出?

标签 jquery ajax

我有一个使用 AJAX 和 PHP 将数据插入数据库的表单。

AJAX

function insertBill()
{
    $.post('insert_bill.php', $('#insertbill').serialize(), 
        function(data) {
        $('#bills').append(data);
    });
};

是否可以使用 jQuery 让我的数据淡入 #bills div 中?

最佳答案

您可以使用以下不同的变体:

function insertBill() {
    $.post('insert_bill.php', $('#insertbill').serialize(), 
        function(data) {
        $('#bills').hide().append(data).fadeIn("slow");
    });
}

您还可以在网站加载时通过 css 隐藏#Bills,或者您可以在提交时隐藏它,如下所示:

function insertBill() {
    $.ajax({
        url: 'insert_bill.php',
        data: $('#insertbill').serialize(),
        type: 'post', 
        beforeSend: function(jqXHR, settings) {
            $('#bills').hide();
        },
        success: function(data, textStatus, jqXHR) {
            $('#bills').append(data).fadeIn("slow");
        },
    });
}

关于jquery - 在 AJAX 请求中使用 jQuery 淡入淡出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10322640/

相关文章:

javascript - 两行类似的代码,一行有效,另一行无效。为什么不?

ajax - 在RemoteFunction内部为一个参数传递两个值

javascript - Laravel 和 Ajax - 将数据插入表而不刷新

javascript - 访问 jQuery/AJAX 请求中的变量/数据?

javascript - 如何在 native JS 中使用 AJAX 保持 PHP session 处于事件状态?

javascript - anchor 标记弹出一个 div 而不是一个新页面

javascript - 提交后清除我的表单输入

javascript - 当我将鼠标悬停在它的子 div 元素上时,我可以隐藏父 div 吗?

javascript - 如何正确插入 div 以从 jQuery 操作它们?

javascript - AJAX POST 丢失对模型属性的引用 - Spring