나는 두 가지 문제가 있습니다. 아약스 요청을하면 잘 처리되지만 상태는 1 초를 기다리고 있습니다. 그것은 나에게 정말로 높게 보인다. 여기 아약스가 1 초 이상 기다리는 이유는 무엇입니까?
여기내가 사용하고있는 아약스 기능입니다 크롬에서 네트워크 탭의 스크린 샷이다.
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;
});
}
아약스는 자체적으로 "대기"하지 않습니다. 서버가 데이터를 보내면 반응합니다. 진정으로 묻는 질문은 '왜 요청을 처리하기 위해 1 초 이상 걸리는지'입니다. –
서버가 요청을 처리하고 처리하는 데 1 초가 걸립니까? 여러분이보고있는 것은 자바 스크립트 코드 실행의 프로파일 링이 아니라 네트워크 요청/응답입니다. AJAX는 서버가 응답하지 않아 대기 중입니다. – David
이것은 일관된 문제입니까? 연결 속도가 느릴 수도 있습니다. 또한 서버가 무엇이든 할 수 있습니다. –