javascripte发送请求
来源:互联网 发布:中国象棋ai算法 html5 编辑:程序博客网 时间:2024/06/05 16:53
参考:http://blog.csdn.net/sz_bdqn/article/details/3863293
使用XMLHttpRequest对象分为4部完成:
1.创建XMLHttpRequest组建
2.设置回调函数
3.初始化XMLHttpRequest组建
4.发送请求
实例代码:
- var userName;
- var passWord;
- var xmlHttpRequest;
- //XmlHttpRequest对象
- function createXmlHttpRequest(){
- if(window.ActiveXObject){ //如果是IE浏览器
- return new ActiveXObject("Microsoft.XMLHTTP");
- }else if(window.XMLHttpRequest){ //非IE浏览器
- return new XMLHttpRequest();
- }
- }
- function onLogin(){
- userName = document.f1.username.value;
- passWord = document.f1.password.value;
- var url = "LoginServlet?username="+userName+"&password="+passWord+"";
- //1.创建XMLHttpRequest组建
- xmlHttpRequest = createXmlHttpRequest();
- //2.设置回调函数
- xmlHttpRequest.onreadystatechange = zswFun;
- //3.初始化XMLHttpRequest组建
- xmlHttpRequest.open("POST",url,true);
- //4.发送请求
- xmlHttpRequest.send(null);
- }
- //回调函数
- function zswFun(){
- if(xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200){
- var b = xmlHttpRequest.responseText;
- if(b == "true"){
- alert("登录成功!");
- }else{
- alert("登录失败!");
- }
- }
- }
- javascripte发送请求
- JAVASCRIPTE
- 网络请求---NSURLConnection发送请求
- C#发送HTTP请求
- C# 发送请求
- 3.2 发送请求参数
- java 发送http请求
- 发送请求参数
- socket 发送http请求
- 使用FiddlerScript发送请求
- IWebBrowser2 发送post请求
- python发送HTTP请求
- WebClient发送POST请求
- 异步发送HTTP请求
- python发送HTTP请求
- 页面发送action请求
- Qt发送HTTP请求
- android发送get请求
- 构造函数中的成员初始化的执行效率
- mysql管理shell
- 逐步设置vim C/C++语法高亮显示和自动缩进
- PC安卓模拟器PANIC: Could not open:C:\Documents and Settings\Administrator\.android/avd/my_avd.ini解决方案 .
- 在装dg环境时运用到了scp命令
- javascripte发送请求
- ACTIVE日志损坏(有归档)
- 用VBScript读写INI配置文件(比较不错的代码)http://www.robvanderwoude.com/vbstech_files_ini.php
- C/C++中static关键字详解
- 面试训练 n个骰子的点数
- 百度提示”该网站可能因黑客侵入而存在安全风险”的3种解决方案
- html中事件调用JavaScript函数时有return与没有return的区别
- stl-vector
- 心醉七夕