function submitForm(){
var xmlHttp = createXmlHttp();
if (!xmlHttp) {
alert( "您的浏览器不支持AJAX!" );
return 0;
}
var url = ‘phpmail.php‘ ;
var postData = "" ;
postData = "username=" + document.getElementById( ‘username‘ ).value;
postData += "t=" + Math.random();
xmlHttp.open( "POST" , url, true );
xmlHttp.setRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" );
xmlHttp.onreadystatechange = function () {
alert(xmlHttp.status);
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
if (xmlHttp.responseText == ‘1‘ ) {
alert( ‘post successed‘ );
}
}
}
xmlHttp.send(postData);
}
function createXmlHttp() {
var xmlHttp = null ;
try {
//Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
} catch (e) {
//IE
try {
xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP" );
} catch (e) {
xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
}
}
return xmlHttp;
}
|