我有一个问题。当我发出 ajax 请求时,一切正常,但状态正在等待超过 1 秒。这对我来说似乎真的很高。
这是chrome中网络选项卡的屏幕截图
这是我正在使用的 ajax 函数。
function subCommentSubmit() {
$('.subComment').on('submit', function() {
var url = "/laravel/public/utility/submitsubcomment"; // the script where you handle the form input.
// Submits the data with ajax, method type is POST
var currentElement = $(this);
var thatPar = currentElement.parent().parent();
var liveSubCommSection = $('> .live-sub-comments', thatPar);
var commentLoader = $('> .loader-comments > .loader', thatPar);
var formData = currentElement.serialize();
$('.new-reply', currentElement).val('').blur().trigger('autosize.resize');
commentLoader.removeClass('hide').fadeIn(250, function() {
$.ajax({
type: "POST",
url: url,
data: formData, // serializes the form's elements.
success: function(data)
{
commentLoader.fadeOut(250, function() {
commentLoader.addClass('hide');
var response = JSON.parse(data);
var commentPost = $('<li class="single-user-reply"> <div class="user-ava-cont"> <a href="'+ response.userid +'" class="user-ava-a"><img src="../images/avatest1.png"> </a> </div><div class="s-w-user-details"><a href="'+ response.userid +'" class="s-w-poster upop">'+ response.username +' </a> <span class="s-w-timestamp">1 second ago</span><a href="#" class="likes-but notliked active">Like</a> <a href="#" class="likes-but liked">Liked</a><ul class="more-dropdown-cont" role="button"> <li class="dropdown minidrop"><button class="more-dropdown dropdown-toggle" role="button" data-toggle="dropdown"><i class="icon down"></i></button><ul class="dropdown-menu" role="menu" aria-labelledby="people"><li role="presentation"><a class="u-a-a" role="menuitem" tabindex="-1" href="#">Block User</a></li><li role="presentation"><a class="u-a-a" role="menuitem" tabindex="-1" href="#">Report Abuse</a></li></ul></li></ul><div class="s-w-user-post">'+ response.comment +'</div><div class="clear"></div></div></li>');
commentPost.hide();
liveSubCommSection.append(commentPost.fadeIn(250));
subCommentSubmit();
});
}
});
});
currentElement.unbind('submit');
// Ensures it doesn't route the form the normal way, and ajax takes over
return false;
});
}