Ajax 통신 원리 XML HttpRequest

2121 단어 Ajax통신 원리
분명히 AJax 는 JavaScript 스 크 립 트 를 이용 하여 데 이 터 를 방문 하 는 기술 이다.AJAX 는 웹 페이지 를 비동기 로 업데이트 합 니 다.이것 은 전체 웹 페이지 를 다시 불 러 오지 않 고 웹 페이지 를 부분 업데이트 하 는 것 이다.XMLHttpRequest 는 AJAX 의 관건 입 니 다.현재 브 라 우 저 는 XMLHttpRequest 대상(IE5 와 IE6 는 ActiveXObject 를 사용 합 니 다)을 지원 합 니 다.배경 에 데 이 터 를 요청 하 는 ready State 는 5 개의 상태 가 있 습 니 다.0:서버 가 초기 화 되 지 않 았 습 니 다.1:서버 연결 이 완료 되 었 습 니 다.2 요청 이 받 아들 여 졌 습 니 다.3 요청 처리 중 4 요청 이 완료 되 었 습 니 다.상 태 를 바 꿀 때마다 onready statechange 이 벤트 를 한 번 촉발 할 수 있 습 니 다.status 는 두 가지 상태 가 있 습 니 다.200:"OK",404:"페이지 를 찾 지 못 했 습 니 다"아래 Ajax 프론트 데스크 톱 실현 코드 를 보 겠 습 니 다.
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title> </title>
<script type="text/javascript">
function getName(){
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
alert(" :"+xmlhttp.responseText);
}
}
xmlhttp.open("post","Default.aspx?id=gname",true);
xmlhttp.send();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div> <input id="Button1" type="button" value="button" onclick="getName()" /></p>
&nbsp;</div>
</form>
</body>
</html>
배경 코드:
 
protected void Page_Load(object sender, EventArgs e)
{
if (Request["id"]!=null)
{
Response.Write(" ");
Response.End();
}
}
실행 결과:다음 그림 과 같 습 니 다.
첨부 코드 다운로드다음 에 Jquery 가 어떻게 비동기 적 으로 데 이 터 를 요청 하 는 지 봅 시다.

좋은 웹페이지 즐겨찾기