【发布时间】:2009-10-14 11:00:29
【问题描述】:
我正在尝试对我们编写的一些 Ajax 代码进行一些测试,现在显然在本地测试时它运行得非常快而且很棒。我需要强制延迟 3 秒,以便我可以看到加载程序正在显示并且用户体验足够好。
我已尝试以下方法,但收到错误“无用的 settimeout”,还有什么其他建议可以实现此目的吗?有浏览器插件吗?
$('#formAddPost').submit(function() {
//Load the values and check them
var title = $(this).find('#Title');
var description = $(this).find('#Description');
var catId = $(this).find('#Categories');
if (ValidateField(title) == false || ValidateField(description) == false) {
$('.error-message').show();
return false;
}
$('.error-message').hide();
//Show the loading icon
$('.add-post').hide();
$('.add-post-loader').show();
//Temp for testing - allows the showing to the loader icon
setTimeout(MakeAJAXCall(title.val(), catId.val(), description.val()), 1500);
return false;
});
function MakeAJAXCall(title, catId, description) {
$.ajax({
url: "/Message/CreatePost/",
cache: false,
type: "POST",
data: ("title=" + title + "&description=" + description + "&categories=" + catId + "&ajax=1?"),
dataType: "html",
success: function(msg) {
$('#TableMessageList').replaceWith(msg);
$('.add-post-loader').hide();
$('.add-post').show();
}
});
}
【问题讨论】:
标签: ajax