惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
T
Threat Research - Cisco Blogs
S
SegmentFault 最新的问题
V2EX - 技术
V2EX - 技术
Hacker News: Ask HN
Hacker News: Ask HN
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
P
Proofpoint News Feed
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
C
Cybersecurity and Infrastructure Security Agency CISA
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
U
Unit 42
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
H
Help Net Security
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 热门话题
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
H
Heimdal Security Blog
博客园 - 聂微东
S
Securelist
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
Cisco Talos Blog
Cisco Talos Blog

博客园 - Shanks

Linux 内核中的 GCC 特性(zz) makefile strace工具 doxygen&make&智能指针 最近项目的一些技术问题 The ultimate jQuery Plugin List 关于html和javascript在浏览器中的加载顺序问题的讨论(zz) Yahoo!网站性能最佳体验的34条黄金守则——服务器(zz) 今日随笔(2008-08-27) Request-Line解释 下载了最新版本的live writer,在cnblogs上post一下试试 C++二维数组new小结(zz) rfc2616http协议笔记(1) 开始整理读书笔记 Atlas学习之一:学习轨迹及学习资料收集 OLAP和OLTP的区别(基础知识) XSLT分析之一:XPath表达式 JavaScript:QueryString(zz加解释) js文件路径问题
第一个Ajax小程序,了解Ajax原理
Shanks · 2006-08-13 · via 博客园 - Shanks

今天看<ajax基础教程>,开始学习ajax底层的一些东西,对理解atlas会有帮助。下面是ajax最简单的代码
----innerHTML.htm----

<!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>
    
<title>User ResponseText With innerHTML</title>
    
<script type="text/javascript">
    
var xmlHttp;//声明全局XmlHttpRequest
    
function createXMLHttpRequest() //创建一个xmlhttprequest
    
{
        
if(window.ActiveXObject)//IE浏览器把xmlhttprequest看成一个activeX控件。
        
{
            xmlHttp
= new ActiveXObject("Microsoft.XMLHTTP");
        }

        
else//其他浏览器
        
{
            xmlHttp
= new XMLHttpRequest();
        }

    }

    
    
function startRequest()
    
{
        createXMLHttpRequest();
        xmlHttp.onreadystatechange
=handleStateChange;//设定请求状态改变时,响应的函数
        xmlHttp.open(
"GET","innerHTML.xml",true);//建立调用,向innerHTML.xml发送请求,innerHTML.xml模拟服务器
        xmlHttp.send();//发送请求
    }

    
    
function handleStateChange()
    
{
        
        
if(xmlHttp.readyState==4)//请求完成,0=未初始化;1=正在加载;2=已加载;3=交互中;4=完成
        
{
                       
if(xmlHttp.status==200)//请求状态,200为正常返回。
            
{
                document.getElementById(
"results").innerHTML=xmlHttp.responseText;//返回文本绘制页面
            }

        }

    }

    
</script>
</head>
<body>
<form action="#">
<input type="button" value="click me" onclick="startRequest();"/>
<div id="results"></div>
</form>
</body>
</html>

---innerHTML.xml

<table border="1">
<tr>
<th>Activity Name</th>
<th>Location</th>
<th>Time</th>
</tr>
<tr>
<th>WaterSkiing</th>
<th>Dock #1</th>
<th>9:00 AM</th>
</tr>
<tr>
<th>WaterSkiing</th>
<th>Dock #1</th>
<th>9:00 AM</th>
</tr>
<tr>
<th>WaterSkiing</th>
<th>Dock #1</th>
<th>9:00 AM</th>
</tr>
</table>

一个XmlHttpRequest与普通的Http请求流程上没有太大的差别,具体分为:
1.open():建立对服务器的调用,这里设定调用是异步还是同步,这里的异步也就是Ajax里面那个大A。设定为同步,处理只有等待服务器返回相应才继续。一般情况下设定为True,这才与XmlHttpRequest初衷相符合。
2.send(content):向服务器发送请求。
3.得到responseText或者responseXml进行处理。
以上代码对各步骤进行了说明。Ajax核心就是处理XmlHttpRequest对象,深入学习,需要对javascript面向对象编程有深入的了解。这样可以把js代码与html完全分离,实现自己的业务逻辑。