"成功的Axios调用未显示相应的消息"
P粉399090746
P粉399090746 2023-09-13 09:06:49
[JavaScript讨论组]

我不知道如何获取Axios调用成功的响应并显示成功消息。

有一个名为"Change Workflow Order"的按钮,它有一个onClick函数。

这是onClick函数。changeWorkflowOrder函数运行一个Axios调用。

function changeWorkflowOrder() {

    const response = axios.post(js_site_url + '/sort-detail', $('#sortable').sortable("toArray"), {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

我想捕获Axios调用的成功响应,如果Axios调用的响应成功,则在HTML span标签中显示成功消息。消息必须只显示4秒。4秒后,成功消息必须隐藏。

我尝试创建这个。这是我尝试的changeWorkflowOrder函数。

function changeWorkflowOrder() {
    const response = axios.post(js_site_url + '/sort-detail', $('#sortable').sortable("toArray"), {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    });

    response.then((result) => {
        $("#alert_msg").html(result.data.success ? "Success" : "Order change successfully");

        clearTimeout(timeoutId);

        timeoutId = setTimeout(function() {
            $("#alert_msg").hide();
        }, 4000);
    });
}

这段代码正确显示错误消息。但是4秒后显示错误消息后,"Order change successfully"消息没有隐藏,我认为Axios调用响应捕获部分不正确。

我如何捕获Axios调用的响应,并在HTML span标签中显示4秒的成功消息。

P粉399090746
P粉399090746

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号