[JSP] 파일업로드 로딩 화면 샘플 소스 DEMO

2018. 4. 2. 14:51·JS/JavaScript
728x90
반응형

css

/* pop_up */
.pop_wrap { overflow:visible; position:absolute; top:50%; left:50%; display:none; margin-left:-200px; z-index:999; }
.pop_wrap .bg { background:#000; opacity:.5; filter:alpha(opacity=50); width:100%; height:100%; position:fixed; left: 0;top:0; } 
.ly_pop { position:relative; z-index:10; padding:20px; border:2px solid #777; background:#fff; text-align:center;  font-weight:700;}
.ly_pop p { margin:20px 0; padding:20px 0; background:#eaeaea; text-align:center; }
.pop_btn a { display:inline-block; padding:5px 30px; font-size:16px; border:1px solid #ccc; border-radius:3px; }
 
 

header.jsp

<%--접수시 업로딩 --%>
<div id="uploading" class="pop_wrap" style="top:250%;">
    <div class="bg"></div>
    <div class="layer_pop2">
        <p class="percent"><span id="progress">75</span></p>
    </div>
</div>
 
js
function layer_open(el, val){
    var temp = $('#' + el);        //레이어의 id를 temp변수에 저장
    var bg = temp.prev().hasClass('bg');    //dimmed 레이어를 감지하기 위한 boolean 변수

    if(bg){
        $('.pop_wrap').fadeIn();
    }else{
        temp.fadeIn();
    }

    if (temp.outerHeight() < $(document).height() ) temp.css('margin-top', '-'+temp.outerHeight()/2+'px');
    else temp.css('top', '0px');
    if (temp.outerWidth() < $(document).width() ) temp.css('margin-left', '-'+temp.outerWidth()/2+'px');
    else temp.css('left', '0px');

    /*
    temp.find('a.cbtn, a.cbtn2').click(function(e){
        if(bg){
            $('.pop_wrap').fadeOut();
        }else{
            temp.fadeOut();
        }
        e.preventDefault();
    });
    */

    $('.pop_wrap .bg').click(function(e){
        $('.pop_wrap').fadeOut();
        e.preventDefault();
    });

    $('.pop_btn a').click(function(e){
        $('.pop_wrap').fadeOut();
        e.preventDefault();
    });

}
 
fileupload.js
function fileUpload(fileObject, type) {

        var max = 10;
        
        
        var fName = $(fileObject).prop("name");
        var index = fName.substring(fName.length-1,fName.length);
        var productType = $(':input[name=productType' + index + ']:radio:checked').val();
        var type = "";
        
        switch (productType) {
        /* case "2" :
        case "3" :
            type = "img";
            break; */
        default :
            type = "";
            break;
        }
        
       
       if(!fileCheck(fileObject, type)){ 
          delWorks(fileObject);
          return false;
       }
       if(!fileSizeCheck(fileObject, max)) {
          delWorks(fileObject);
          return false;
       }
        
        fnResultInitialize();
        
        var formData = new FormData();
        var files = fileObject.files;
        for (var i = 0; i < files.length; i++) {
            formData.append($(fileObject).attr('name'), files[i]); //업로드한 파일을 하나하나 읽어서 FormData 안에 넣는다.
        }
        
        var callUrl = "/worksUpload.do";
        var xhr = new XMLHttpRequest();
        xhr.open("POST", callUrl, true);
        xhr.upload.onprogress = function(e) {
            layer_open1("uploading");
            var percentComplete = (e.loaded / e.total) * 100;
            progress.innerText = " " + parseInt(percentComplete) + "%";
            if(percentComplete == 100){
                setTimeout(function() {$('.pop_wrap').fadeOut()}, 2000);
            }
        };
        xhr.onload = function() {
            var callStatus = xhr.status;
            if(callStatus == 200){
                var json = JSON.parse(xhr.responseText);
                var target = json.fileName + '_fileIdx';
                $('[name="' + target + '"]' ).val(json.fileIdx);
                frmObj.target.value = json.fileIdx;
            }else {
                alert("오류가 발생했습니다.");
            }
        };
        xhr.send(formData);
        
    }

 

 

 

728x90
반응형

'JS > JavaScript' 카테고리의 다른 글

[JavaScript] Session(세션, feat. SessionStorage), LocalStorage(로컬스토리지), Cookie(쿠키), 사용하기  (0) 2022.11.30
[JSP][HTML][timeleaf] Javascript 전역 함수 사용법  (0) 2018.05.04
[JQuery] [ajax] 04. ajaxMethod  (0) 2017.08.28
[JS] 13. Closure  (0) 2017.08.28
[JS] 12. scope  (0) 2017.08.28
'JS/JavaScript' 카테고리의 다른 글
  • [JavaScript] Session(세션, feat. SessionStorage), LocalStorage(로컬스토리지), Cookie(쿠키), 사용하기
  • [JSP][HTML][timeleaf] Javascript 전역 함수 사용법
  • [JQuery] [ajax] 04. ajaxMethod
  • [JS] 13. Closure
밍글링글링
밍글링글링
mingling - 밍글링, 밍글밍글링. 코드와 어우러지다. IT/ 프로그래밍/소스
    반응형
    250x250
  • 밍글링글링
    mingling
    밍글링글링
  • 전체
    오늘
    어제
    • 밍글링글링 (463)
      • Flutter (2)
      • 일상생활 (8)
        • 리뷰 (1)
        • 생활정보 (4)
        • 맛집 (0)
        • 여행 (0)
        • 모든정보 (3)
      • JAVA (126)
        • 개념 (6)
        • 예제 (115)
        • Exception (2)
      • C (1)
        • C (1)
        • C++ (0)
        • C# (0)
      • JS (29)
        • JavaScript (18)
        • JQuery (5)
        • AJax (0)
        • NODE.JS (6)
        • Angular.JS 2.0 (0)
      • WEB (87)
        • HTML (6)
        • CSS (61)
        • JSP (20)
        • JSTL (0)
      • FrameWork (8)
        • Spring (8)
        • BootStrap (0)
        • MyBATIS (0)
        • JUnit (0)
      • 외부 라이브러리 (5)
      • 공유 소스 관리 (5)
        • Git (5)
        • SVN (0)
      • 빅데이터 프로그래밍 (37)
        • Python (37)
        • R Programming (0)
      • DB (7)
        • ORACLE (0)
        • MySql (6)
      • Development Tools (7)
        • StarUML (0)
        • eXERD (0)
        • Eclipse (4)
      • SKILL (6)
        • Migration (0)
        • Security (6)
      • MicroSoft (0)
        • Excel (0)
        • Word (0)
      • Android (0)
      • Server (21)
        • Ubuntu (5)
        • Linux (15)
      • IOS (0)
      • XML (0)
      • 미디어 (0)
      • 공지사항 (3)
      • NETWORK (1)
      • 게임 (4)
        • 피파 (1)
        • 리니지M (0)
        • 배틀그라운드 (1)
        • 듀랑고 (2)
      • 세상 이슈 (6)
      • 일렉트론 (0)
      • 대회 소식 (4)
      • 업무 (2)
      • Express, Vue (6)
      • docker (11)
      • svelte (3)
      • 블록체인 (1)
      • IT (66)
      • Rust (0)
  • 블로그 메뉴

    • 홈
    • 태그
    • 미디어로그
    • 위치로그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    css table
    프런트엔드
    vue cli
    티스토리 자동화
    vscode
    servlet class
    jsp include
    Rust lang
    자바 클래스
    러스트
    css transition
    API 설계
    SSL 인증서
    mysql db
    제미나이
    VS Code 팁
    ssl 인증서 발급
    css perspective
    자바 배열
    rust linux
    spring java
    클론코딩
    svelte
    proxy pass
    Extension Bisect
    자바 for문
    css float
    java casting
    AI 반도체
    nginx ssl 적용
    AI 코딩 에이전트
    오류
    docker
    리눅스 설치
    nginx ssl 설정
    lang rust
    Node
    브라우저 자동화
    Java Array
    React Compiler
    nginx
    jsp parameter
    gitlab 설치
    자바 exception
    css tb
    vue 설치
    자바 객체 지향
    자바 생성자
    ubuntu
    에디터 팁
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
밍글링글링
[JSP] 파일업로드 로딩 화면 샘플 소스 DEMO
상단으로

티스토리툴바