대부분의 경우 은에 2 페이지가 있습니다. 첫 번째 페이지 인 클라이언트 쪽은 서버 쪽 다른 페이지로 전화를 걸고 기다리는 동안 꽤 돌아가는 것을 보여줍니다. 서버 측 페이지 로딩이 끝나면 (쿼리가 완료되면) 첫 번째 페이지가 응답을받은 다음 예쁜 스핀을 숨겨서 사용자에게 완료되었음을 알릴 수 있습니다.
순수한 자바 스크립트 또는 jQuery에서 더 간단한 AJAX를 사용하여 PHP 페이지의 일부 데이터를 동적으로로드하고 기다리는 동안 회전하는 것을 표시 할 수 있습니다. 여기 jQuery를 사용했습니다.
CSS
#loading_spinner { display:none; }
HTML
<img id="loading_spinner" src="loading-spinner.gif">
<div class="my_update_panel"></div>
jQuery를
$('#loading_spinner').show();
var post_data = "my_variable="+my_variable;
$.ajax({
url: 'ajax/my_php_page.php',
type: 'POST',
data: post_data,
dataType: 'html',
success: function(data) {
$('.my_update_panel').html(data);
//Moved the hide event so it waits to run until the prior event completes
//It hide the spinner immediately, without waiting, until I moved it here
$('#loading_spinner').hide();
},
error: function() {
alert("Something went wrong!");
}
});
PHP (my_php_page.php)
<?php
// if this page was not called by AJAX, die
if (!$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') die('Invalid request');
// get variable sent from client-side page
$my_variable = isset($_POST['my_variable']) ? strip_tags($_POST['my_variable']) :null;
//run some queries, printing some kind of result
$SQL = "SELECT * FROM myTable";
// echo results
?>
실제로이 쿼리는 시간이 걸리는 것처럼 보이지 않습니다. 그것이 전부입니까? –
약 3-4 초 걸립니다. – Lmxc
한 행을 쿼리 하시겠습니까? 그건 맞지 않아. –