| | |
|
|
|
book.jsp ==============================
<?xml version="1.0" encoding="euc-kr" ?> <%@ page contentType="text/xml; charset=EUC-KR"%>
<books> <book> <title>성공적인 웹 프로그....</title> <author>아무개</author> </book> <book> <title>웹 프로그....</title> <author>무</author> </book> <book> <title>로그....</title> <author>개</author> </book>0 </books>
|
httpReq.js=====================================
function getXMLRequest(){ if(window.ActiveXObject){ try{ return new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try{ return new ActiveXObject("Microsoft.XMLHTTP"); }catch(e1){ return null; } } }else if(window.XMLHttpRequest){ return new XMLHttpRequest(); }else{ return null; } }
var httpRequest = null ;
function sendRequest(url, params, callback, method){ httpRequest = getXMLRequest();
var httpMethod = method?method:'GET'; if(httpMethod != 'GET' && httpMethod != 'POST'){ httpMethod = 'GET'; } var httpParams = (params == null || params=='')?null:params; var httpUrl = url ; if(httpMethod == 'GET' && httpParams != null){ httpUrl = httpUrl+"?"+httpParams } httpRequest.open(httpMethod, httpUrl, true); httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); httpRequest.onreadystatechange = callback; httpRequest.send(httpMethod=='POST'?httpParams:null); }
|
view.html=========================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">
<head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <script type="text/javascript" src="httpReq.js"></script> <script type="text/javascript"> function loadBooks(){ sendRequest("book.jsp", null, loadedBooks, "GET"); }
function loadedBooks(){ if(httpRequest.readyState==4){ if(httpRequest.status==200){
var xmlDoc = httpRequest.responseXML; var bookList = xmlDoc.getElementsByTagName("book"); var message = "총 개수 :"+bookList.length+"권\n";
for(i=0; i<bookList.length; i++){ var book = bookList.item(i); var title = book.getElementsByTagName("title").item(0).firstChild.nodeValue; var author =book.getElementsByTagName("author").item0).firstChild.nodeValue; message += title+"("+author+")\n"; }
document.getElementById("here").innerHTML=message ;
} } } window.onload=function(){ loadBooks(); }
</script> <title>Insert title here</title> </head> <body> <div id="here"></div> </body> </html>
|
결과 ======================================== 총 개수 :3권 성공적인 웹 프로그....(아무개) 웹 프로그....(무) 로그....(개)
| |
|
|
|
|
|
| http://laedu.net/trackback/7 | |
| |
|
| |
| | |
|
|
| |
| | |
|
|
|
| | 웹기반 프로그래밍에 관한 것들을 모을 예정이었는데.. | | |
|
|
| |
«
2024년 11월
»
일 |
월 |
화 |
수 |
목 |
금 |
토 |
|
|
|
|
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
| | |
|
|