发送http请求
来源:互联网 发布:ubuntu安装openjdk1.8 编辑:程序博客网 时间:2024/05/22 06:43
见http://www.informit.com/articles/article.aspx?p=669066&seqNum=2
,附内容:
XMLHttp.open("GET", "phrasebook.txt");XMLHttp.onreadystatechange = handlerFunction;XMLHttp.send(null);
Sending an HTTP request to a server using XMLHttpRequest consists of the following steps:
- Provide the URL and the HTTP verb to use.
- Define a callback function when results arrive.
- Send the request.
Step 1 can be taken with the open() method of the XMLHttpRequest object. This does not—unlike what the method name suggests—actually open an HTTP connection, but just initializes the object. You provide the HTTP verb to use (usuallyGET or POST) and the URL.
Step 2, the callback function, is provided to the onreadystatechange property of the object. Whenever thereadyState property ofXMLHttpRequest changes, this callback function is called. Finally, thesend() method sends the HTTP request.
In the callback function, the readyState value 4 represents the state of the object we want: call completed. In that case, theresponseText property contains the data returned from the server.
Here is a fully working example, sending a GET request to the server (a file calledphrasebook.txt with simple text content) and evaluating the response of that call:
Sending a GET Request (xmlhttpget.html)
<script language="JavaScript" type="text/javascript" src="xmlhttp.js"></script><script language="JavaScript" type="text/javascript">var XMLHttp = getXMLHttp();XMLHttp.open("GET", "phrasebook.txt");XMLHttp.onreadystatechange = handlerFunction;XMLHttp.send(null);function handlerFunction() { if (XMLHttp.readyState == 4) { window.alert("Returned data: " + XMLHttp.responseText); }}</script>
- C#发送HTTP请求
- java 发送http请求
- socket 发送http请求
- python发送HTTP请求
- 异步发送HTTP请求
- python发送HTTP请求
- Qt发送HTTP请求
- socket发送http请求
- 发送http请求
- JAVA发送HTTP请求
- python发送HTTP请求
- c++ 发送http请求
- Qt发送http请求
- Qt发送HTTP请求
- 模拟发送http请求
- 发送http请求
- android发送http请求
- python发送http请求
- Emacs org-mode
- 纯虚函数及抽象类
- 硬件系统设计:该用FPGA来做呢还是用单片机?
- C#winform 打印图像,PrintDialog打印并且设置打印纸张大小
- JSP的四个作用域
- 发送http请求
- Spring 实现文件上传与下载
- poj1730
- 手动插int 3实现程序主动断点
- C setjmp和longjmp
- DLL:VS2005使用C++制作dll文件
- 世界最小的高清玩具单反数码相机
- firefox event.srcElement
- NeatUpload的web.config配置