간단 한 AJAX 비동기 처리

14568 단어 Ajax

  
    
1 <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
2   < html xmlns ="http://www.w3.org/1999/xhtml" >
3   < head >
4   < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
5   < title > </ title >
6 < script type ="text/javascript" >
7 var xmlHttp;
8 function createXMLHttpRequest()
9 {
10 if (window.ActiveXObject) //
11 {
12 xmlHttp = new ActiveXObject( " Microsoft.XMLHTTP " ); //
13 }
14 else if (window.XMLHttpRequest)
15 {
16 xmlHttp = new XMLHttpRequest();
17 }
18 }
19 function startRequest()
20 {
21 createXMLHttpRequest(); //
22 xmlHttp.onreadystatechange = function () //
23 {
24 if (xmlHttp.readyState == 4 ) //
25 {
26 var a = xmlHttp.responseText; // a
27 alert(a)
28 }
29 }
30 xmlHttp.open( " GET " , " admin.php " , true ); // GET URL
31 xmlHttp.send( null ); //
32 }
33 </ script >
34 </ head >
35
36 < body >
37 < input type ="button" value =" " onclick ="startRequest()" />
38 </ body >
39 </ html >
40
41 admin.php
42 <? php
43 echo "my name is youyou"
44 ?>

  요약:
1:브 라 우 저 를 판단 하고 XML HttpRequest 대상 을 예화 합 니 다.
2:해당 서버 에서 실 행 된 코드 세그먼트;
3:open 방법 으로 서버 스 크 립 트 언어 에 접근 하 는 요청 을 만 듭 니 다.
4:이 요청 을 send 방법 으로 보 내기;
 

좋은 웹페이지 즐겨찾기