Frontend/Ajax
Ajax 코딩 절차
by 지구
2018. 5. 17.
* Ajax 코딩 절차
① XMLHttpRequest 생성
② HttpProtocol 구성
③ Callback Function 지정
④ Request.send(data/null)
⑤ Callback Function 구현
* 예제
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 31 32 | var request = null; function createRequest(){ try{ request = new XMLHttpRequest(); }catch(trymicrosoft){ try{ request = new ActiveXObject("Msxml2.XMLHTTP"); }catch(othermicrosoft){ try{ request =new ActiveXObject("Microsoft.XMLHTTP"); }catch(failed){ request = null; } } } if( request == null ){ alert ("request객체 생성시 error 발생함."); } } function getSold(){ createRequest(); var url = "calcServerAjax.jsp"; request.open("GET",url,true); //비동기 request.onreadystatechange = updatePage; request.send(null); } | cs |
댓글