在创建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 });
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
这是一个实例 =- = 简单明了~