gpt4 book ai didi

jquery - 为什么POST回调函数不起作用

转载 作者:行者123 更新时间:2023-12-01 03:27:40 24 4
gpt4 key购买 nike

我正在尝试执行以下操作 fadeIn/fadeOut action在 jQuery $.post 函数中。

$.post('Scenario/SaveScenario', function (data) {
$('<div class="save-alert">The current scenario has been saved.</div>')
.insertAfter($('.buttons'))
.fadeIn('slow')
.animate({ opacity: 1.0 }, 2000)
.fadeOut('slow', function () {
$(this).remove();
});
});

但是,这不起作用并且(显然)什么也没有发生。 (我在 Firebug 中的函数内放置了一个断点,但从未到达该断点。)随着场景被放入我的数据库,该帖子正在成功发生。我不认为这是问题所在。

我通过将其添加为提交按钮上的单击事件来对其进行了测试,并且确实有效。

$(function () {
$('#SaveScenario').click(function () {
$('<div class="save-alert">The current scenario has been saved.</div>')
.insertAfter($('.buttons'))
.fadeIn('slow')
.animate({ opacity: 1.0 }, 2000)
.fadeOut('slow', function () {
$(this).remove();
});
});
});

关于我做错了什么有什么理论吗?

最佳答案

来自 jQuery 文档:

If a request with jQuery.post() returns an error code, it will fail silently unless the script has also called the global .ajaxError() method.

所以帖子可能会很好地到达服务器并通过,但是当帖子返回到 jQuery 时可能会出现某种错误(可能是意外的数据形式)或者返回途中可能会出现一般类型的错误(错误的响应代码)?尝试使用 jQuery.ajax 发送请求,并为其提供一个 error 处理程序以查看是否发生某种错误。例如,如果您使用 ajaxSetup 并将 dataType 设置为 json 并且您没有从服务器返回有效的 JSON,jQuery 将因以下错误而终止:解析错误。

只需点击http://your.site.com/Scenario/SaveScenario,您会得到什么?

关于jquery - 为什么POST回调函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3517146/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com