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

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
T
Threat Research - Cisco Blogs
小众软件
小众软件
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
S
Secure Thoughts
O
OpenAI News
P
Proofpoint News Feed
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
T
Tenable Blog
A
Arctic Wolf
L
LINUX DO - 热门话题
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
博客园 - Franky
WordPress大学
WordPress大学
Know Your Adversary
Know Your Adversary
博客园_首页
雷峰网
雷峰网
IT之家
IT之家
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
H
Heimdal Security Blog

博客园 - L.Zhang

.Net Remoting RMI框架 自己开发连接池 JDBC访问数据库 MyEclipse下开发Web Service XML CDATA XPath 数据库操作的sql脚本 直接选择排序 直接插入排序 气泡排序 Builder 生成器模式(创建型模式) Abstract Factory 抽象工厂模式(创建型模式) Factory Method 工厂方法模式(创建型模式) Singleton单件模式(创建型模式) 使用Profile Service 服务端如何使用Session 让服务端返回xml 用Get方式访问
使用传统的XMLHttpRequest发出Ajax请求
L.Zhang · 2007-11-10 · via 博客园 - L.Zhang

//客户端脚本

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    
<title>XMLHttpRequest</title>
    
<script language="javascript" type="text/javascript">
        
//根据不同的浏览器,获取XMLHttpRequest对象
        function getXMLHttpRequest()
        {
            
if (window.XMLHttpRequest)
            {
                
return new window.XMLHttpRequest();
            }
            
else
            {
                
var progIDs = [ 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP' ];
        
                
for (var i = 0; i < progIDs.length; i++)
                {
                    
try
                    {
                        
var xmlHttp = new ActiveXObject(progIDs[i]);
                        
return xmlHttp;
                    }
                    
catch (ex) { }
                }
                
                
return null;
            }
        }
        
        
function sendRequest()
        {
            
var xhr = getXMLHttpRequest();
            
//参数为提交方式,和提交地址,是否异步通讯默认为true
            xhr.open("POST""Handlers/RandomNumber.ashx");
            
// xhr.setRequestHeader("header", "value"); 设置头信息
            //设置回调函数
            xhr.onreadystatechange = function()
            {
                onReadyStateChange.apply(xhr);
            }
            
//发送请求
            xhr.send(null);
        }
        
//回调函数
        function onReadyStateChange()
        {   
//判断结果
            if (this.readyState == 4)
            {
                
if (this.status == 200)
                {
                    alert(
this.responseText);
                    
// this.responseXML;
                    // var header = this.getResponseHeader("header"); //获取一个头信息
                    // var headers = this.getAllResponseHeader();     //获取所有头信息
                }
                
else
                {
                    
throw new Error();
                }
            }
        }
    
</script>
</head>
<body>
    
<input type="button" value="Send" onclick="sendRequest()" />
</body>
</html>

//服务器代码RandomNumber.ashx

using System;
using System.Web;public class RandomNumber : IHttpHandler
{
    
private static Random random = new Random(DateTime.Now.Millisecond);
    
    
public void ProcessRequest (HttpContext context)
    {
        context.Response.ContentType 
= "text/plain";
        context.Response.Write(random.Next());
    }
 
    
public bool IsReusable
    {
        
get
        {
            
return false;
        }
    }

}