웹프로그래밍

Global It Leader!!


jQuery


 
 

ajax + asp 데이터 주고 받기

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 4,934회 작성일 12-02-28 15:38

본문

/************************************************************************************************************

postdata.html

*************************************************************************************************************/

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 데이터 송신</title>
<link rel="stylesheet" href="postdata.css" type="text/css" />
<script language="javascript" type="text/javascript" src="commXMLHttp.js"></script>
<script language="javascript" type="text/javascript" src="postdata.js"></script>
</head>

<body>
<h1>데이터 송신</h1>

<div id="dataentry">
    <p> 감명 깊었던 영화를 입력하세요 </p>
    <div>
        제목: <input  type="text" id="cinema" />
    </div>
    <div>
        감독: <input  type="text" id="director" />
    </div>
    <div>
        출연: <input  type="text" id="heroname" />
    </div>
</div>

<div id="entrybtn">
    <input  type="button" id="httpbrw" value="데이터 송신" onclick="initialValueSet()" />
</div>

<h2>서버에서 수신한 데이터</h2>
<div id="datashow"></div>
</body>
</html>


 

/************************************************************************************************************

commXMLHttp.js

*************************************************************************************************************/

 

/*******************************************
공통 함수

불러오는 쪽에서 필요한 함수
mainControl()
********************************************/
// XMLHttpRequest 생성
function newXMLHttpRequest() {
    var reqHttp; 
    if (window.ActiveXObject) {  // IE
        try {
            reqHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                reqHttp =  new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e1) {             
                reqHttp =  null;
            }
        }
    } else if (window.XMLHttpRequest){  // IE 이외
        try {
            reqHttp =  new XMLHttpRequest();
        } catch (e) {
            reqHttp =  null;
        }
    }
    if (reqHttp == null) errorMessage();  //XMLHttpRequest 생성 실패
    return reqHttp;
}

// 지원할 수 없는 브라우저 사용
function errorMessage() {             
    alert("지원할 수 없는 브라우저입니다.");
}

// readyState와 status 체크
function openSendStatus(getPost, urlFileAppl, trueFalse, sendData) {
    var xmlHttp = newXMLHttpRequest();              //XMLHttpRequest 생성
    xmlHttp.open(getPost, urlFileAppl, trueFalse);    //송신방법,URL,통신방법
    xmlHttp.onreadystatechange = function() {      //처리상태 변경 발생
        if (xmlHttp.readyState == 4) {                    //서버 처리 완료
            if (xmlHttp.status == 200) {                  //파일 수신 성공
                mainControl(xmlHttp);                      //메인 처리
            } else {
                exceptionControl(xmlHttp);              //예외 처리
            }
        }
    }
    var conType = "application/x-www-form-urlencoded; charset=UTF-8";
    xmlHttp.setRequestHeader("Content-Type", conType);
    xmlHttp.send(sendData);                          //처리 데이터 송신
}

// 예외 처리 (status != 200)
function exceptionControl(xmlHttp) {
    var exceptShow = "상태 코드: " + xmlHttp.status;
    exceptShow += ",  비정상으로 종료되었습니다.";
    alert(exceptShow);
}

 

/************************************************************************************************************

postdata.js

*************************************************************************************************************/



/*******************************************
commXMLhttp.js 에 포함된 함수

newXMLHttpRequest()
openSendStatus()
exceptionControl()
errorMessage()
********************************************/
// 초기값 세트
function initialValueSet() {

    var getPost = "POST";
    var urlFileAppl = "postdata.asp";
    var trueFalse = true;
    var sendData = dataSetControl(); //전송데이터
    openSendStatus(getPost, urlFileAppl, trueFalse, sendData);
}

//전송 데이터 편집
function dataSetControl() {

 var sendCinema = document.getElementById("cinema").value;
 var sendDirector = document.getElementById("director").value;
 var sendHeroname = document.getElementById("heroname").value;

 sendData = "cinema=" + encodeURIComponent(sendCinema) +
      "&director=" + encodeURIComponent(sendDirector) +
      "&heroname=" + encodeURIComponent(sendHeroname);
 return sendData;


//서버 수신 데이터 출력 & 처리
function mainControl(xmlHttp) {

  var xmlHttpData = decodeURIComponent(xmlHttp.responseText);  // 디코딩
    var splitData = xmlHttpData.split("\n");    //라인 단위로 데이터 분할

    var k, m, returnData, editData="";
    for (k = 0; k < splitData.length; k++) {
        returnData = splitData[k].split("###");
        for (m = 0; m < returnData.length; m++) {
            editData += returnData[m] + "<br />";
        }
    }
  //데이터 출력
    document.getElementById("datashow").innerHTML = editData;
}


 

 

/************************************************************************************************************

postdata.asp

*************************************************************************************************************/

 

<%response.write request("cinema")%>###<%response.write request("director")%>###<%response.write request("heroname")%> 

댓글목록

등록된 댓글이 없습니다.

전체 142
게시물 검색
jQuery 목록
번호 제목 글쓴이 조회 날짜
42 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4523 03-21
41 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4450 03-21
40 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5233 03-15
39 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4614 03-15
38 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5277 03-09
37 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4667 03-08
36 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4345 03-08
35 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4688 03-01
34 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4509 03-01
33 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5023 02-29
32 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4873 02-29
31 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4464 02-29
열람중 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4935 02-28
29 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4562 02-27
28 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4826 02-22
27 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4309 02-26
26 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4409 02-14
25 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4353 02-10
24 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4845 11-23
23 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5456 08-27