Ajax学习-XMLHttpRequest创建,请…

在创建XMLHttpRequest中的时候, 不同浏览器有不同创建方法

01  $ ( document ). ready ( function ()  {
02      $ ( 'input#login_button' ). click (
03          function ()  {
04  //            alert("click");
05              var   username   =   $ ( 'input#username' ). val ();
06              var   password   =   $ ( 'input#password' ). val ();
07              if  ( username   ==   '' {
08                  alert ( "username can't be empty !" );
09                  return  ;
10              }
11              if  ( password   ==   '' {
12                  alert ( "password can't be empty !" );
13                  return  ;
14              }
15              if  ( password . length <</span> 6 || password.length > 16{
16                alert("password's length must be in 6 and 16!");
17                return ;
18            }
19            var xmlhttp;
20            if (window.XMLHttpRequest{
21                xmlhttp = new XMLHttpRequest();
22            }else{
23                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
24            }
25            var url = "username="+username+"&password="+password;
26 //            alert(url);
27            xmlhttp.open("POST","login_result.php",true);
28            xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
29            xmlhttp.onreadystatechange = function() {
30                if (xmlhttp.readyState == 4 && xmlhttp.status == 200{
31                    var Info = xmlhttp.responseText;
32                    if (Info == "true"{
33                        location.href = "index.php";
34                    }else{
35                        alert(Info);
36                    }
37                }
38            }
39            xmlhttp.send(url);
40        }
41        );
42 });

这是一个实例 =- = 简单明了~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值