欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

AJAX簡單測試代碼實(shí)例

 更新時(shí)間:2015年03月30日 17:03:17   作者:xugang  
這篇文章主要介紹了AJAX簡單測試代碼,以一個(gè)簡單實(shí)例分析了Ajax的實(shí)現(xiàn)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了AJAX簡單測試代碼。分享給大家供大家參考。具體如下:

客戶端:代碼如下:(AJAX_test.html )

<!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>無標(biāo)題文檔</title>
<script type="text/javascript">
 var xmlhttp;
 //創(chuàng)建異步對象
 function initXmlHttp(){
   if(window.ActiveXObject){    //IE瀏覽器
     xmlhttp = new window.ActiveXObject("Microsoft.XMLHTTP");
   }
   else if(window.XMLHttpRequest){ //非IE瀏覽器
     xmlhttp = new window.XMLHttpRequest();
   }
 }
 window.onload = initXmlHttp;
 //發(fā)送異步請求
 function sendRequest(){
   //傳入一個(gè) myname 參數(shù) 和 一個(gè)用于解決IE緩存問題的實(shí)時(shí)毫秒數(shù)
   xmlhttp.open("GET","AJAX_servers.aspx?myname=xg&" + new Date().getTime());
   //指定當(dāng)readyState屬性改變時(shí)的事件處理句柄onreadystatechange
   xmlhttp.onreadystatechange = funState;
   xmlhttp.send(null);
 }
 
 //獲取異步結(jié)果
 function funState(){
   if( xmlhttp.readyState == 4)
   {
     if( xmlhttp.status == 200 || //status==200 表示成功!
       xmlhttp.status == 0) //本機(jī)測試時(shí),status可能為0。
     {
       var re = xmlhttp.responseText;
       //alert(re);
       document.getElementById("divShow").innerHTML = re;
     }
   }
 }
</script>
</head>
<body>
<button onclick="sendRequest();">發(fā)送</button>
<div id="divShow"></div>
</body>
</html>

服務(wù)器端:代碼如下:(AJAX_servers.aspx )

復(fù)制代碼 代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AJAX_servers.aspx.cs" Inherits="Web_1.AJAX_servers" %>
<%
    if (Request.HttpMethod == "GET")
    {
        string str = Request.QueryString[0];
        Response.Write(str + ":我是來自服務(wù)器的文字!");
    }
%>

希望本文所述對大家的Ajax程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論