gpt4 book ai didi

php - 为什么ajax等待超过一秒?

转载 作者:行者123 更新时间:2023-12-01 03:42:39 25 4
gpt4 key购买 nike

我遇到了一个问题。当我发出 ajax 请求时,它运行良好,但状态等待了 1 秒多一点。这对我来说似乎真的很高。

这是 Chrome 中网络选项卡的屏幕截图 Network tab

这是我正在使用的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;

});
}

最佳答案

我会分析您的 PHP 文件,因为这似乎是您问题的根源。

我不熟悉 Laravel 的分析选项,但您可以做的简单事情是:

class utility{

function submitsubcomment(){
$start = microtime(true);

//Your code is here

echo (microtime(true) - $start);
}

}

祝你好运!

关于php - 为什么ajax等待超过一秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17730618/

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