ajax 통해 게시판 데이터 불러오기 전까지 로딩 이미지 첨부 기능 구현할려고합니다.

ajax 통해 게시판 데이터 불러오기 전까지 로딩 이미지 첨부 기능 구현할려고합니다.

QA

ajax 통해 게시판 데이터 불러오기 전까지 로딩 이미지 첨부 기능 구현할려고합니다.

답변 1

본문


<td>
 <label>이름 <input type="text" id="sh_u_id" name="sh_u_id" value="<?=$sh_user_id?>"></label>
 <button type="button" onclick="load_list('loading');">조회</button>  // 여기가 start 입니다!!
</td>
 
		<table cellspacing="0"width="100%" style="margin-left: 10px; width: 100%;">
			<thead>
				<th>번호</th>
				<th>이름</th>
				<th>제목</th>
			</thead>
			<tbody id="list_datas"></tbody>
 
</talbe>
<div id="loading_html"></div> 
<script>
$(document).ready(function(){
  var loading = $('<div id="loading" class="loading" style="display:none"><img id="loading_img" alt="loading" src="./img/loading.gif"/ > </div>'); 
  $('#loading_html').append(loading);  // 로딩 이미지 append 하기
 
});
 
 
function load_list(loading){
if(loading) $('#loading').show(); // 검색 통해 ajax 실행되는거면 로딩 이미지 show하기
var sh_u_id = $('#sh_u_id').val();
 $.ajax({
            url: 링크주소.
             data: {"sh_u_id":sh_u_id },
            async: false,
            dataType: "jsonp",
            jsonp: "callback",
            type:"get",
            success: function (response) {
                outputdebugstring(response);
                if (is_success(response)) {  //성공시!!!!!!!
                   
for(var i=0; i<response.lenght; i++){
  
   var html = '<tr>';
html += '<td>'+번호+'</td>';
html += '<td>'+이름+'</td>'; 
html += '<td>'+제목+'</td>';
}
$(#list_datas).append(html); // 게시판 데이터 append 하기
//$('#loading').hide(); // 게시판 데이터 hide 처리 
 
 
                } else {
                    outputdebugstring(response);
                }
            },
            error: function (response) {
                outputdebugstring("load_user_info 호출이 실패 하였습니다.");
                outputdebugstring(response);
            },
            timeout: 30000
 
        });
 
}
</script>

 

 

해당 검색해야 되는 이름 적고 "조회"버튼 눌으면 자바스크립트 load_list 함수로  호출하게되는데

 

여기서 로딩 이미지는 나타나지만 ajax 성공 후 이미지가 이제서야 나옵니다.

 

순서상으로는 ajax 보다 if(loading$('#loading').show();

 

앞에 있기때문에 이렇게 소스 작성했는데요.

 

왜 반응이 늦게 나오나요??

이 질문에 댓글 쓰기 :

답변 1

어떤 브라우져인지는모르겠지만 show() 호출 이후 이미지를 로딩을 시작하며, 이미지 로딩이 좀 길어진 것 같습니다.

로딩 오브젝트를 굳이 append()로 넣어야 하는 이유가 있나요?

그냥 html로 하드코딩하시면 안되나요?

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 14
© SIRSOFT
현재 페이지 제일 처음으로