AJax¼¼Êõ

¶þÊ®ÈýÕ AJAXѧϰ±Ê¼Ç£¨¶þ£©¼ì²âÓû§Ãû

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-11-12 13:01 ÎÒÒªÆÀÂÛ( )

Ò»¡¢zhuce.php html head meta http-equiv=content-type content

Ò»¡¢zhuce.php
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Óû§×¢²á</title>
<script type="text/javascript">
//´´½¨ajaxÒýÇæ
function getXmlHttpObject(){
//²»Í¬µÄä¯ÀÀÆ÷»ñÈ¡xmlhttprequest µÄ·½·¨²»Ò»Ñù
if(window.ActiveXObject){
//window.alert('ie');
xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");
}
else{
//window.alert('ff');
xmlHttpRequest=new XMLHttpRequest();
}
return xmlHttpRequest;
}
var myXmlHttpRequest="";
function checkName(){
myXmlHttpRequest=getXmlHttpObject();//1ºÅÏß
if(myXmlHttpRequest){
//window.alert("´´½¨AjaxÒýÇæ³É¹¦£¡");
//ͨ¹ýmyXmlHttpRequest¶ÔÏó·¢ËÍÇëÇóµ½·þÎñÆ÷µÄijһ¸öÒ³Ãæ
//µÚÒ»¸ö²ÎÊý±íʾÇëÇóµÄ·½Ê½£¬get/post
//µÚ¶þ¸ö²ÎÊýÖ¸¶¨url£¬¶ÔÄǸöÒ³Ãæ·¢³öajaxÇëÇó(±¾ÖÊÈÔÈ»ÊÇhttpÇëÇó)£¬Ö»ÒªÊÇweb¿ª·¢µÄµ×²ãÊÇhttpÇëÇó£¬httpµÄµ×²ãÊÇtcp/ipЭÒé
//µÚÈý¸ö²ÎÊý true ±íʹÓÃÒì²½»úÖÆ£¬false±íʾ²»Ê¹ÓÃÒì²½»úÖÆ¡£
//´ò¿ªÇëÇó
//var url="/ajax/registerPro.php?username="+$("username").value;
//var url="/ajax/registerPro.php?mytime="+new date()+"&username="+$("username").value;
var url="registerPro.php";
//Õâ¸öÊÇÒª·¢ËÍÊý¾Ý
var data="username="+$("username").value;
//window.alert(url);
myXmlHttpRequest.open("post",url,true);
//Õâ¾ä»°²»¿ÉÉÙ
//http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
myXmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//Ö¸¶¨»Øµ÷º¯Êý . chuliÊǺ¯ÊýÃû
myXmlHttpRequest.onreadystatechange=chuli;
//ÕæµÄ·¢ËÍÇëÇó£¬Èç¹ûÊÇgetÇëÇó·¢ËÍnull¼´¿É£»Èç¹ûÊÇpostÇëÇó£¬ÔòÌîÈëʵ¼ÊµÄÇëÇó¼´¿É
//myXmlHttpRequest.send(null); //2ºÅÏß
myXmlHttpRequest.send(data); //2ºÅÏß
}
}
//»Øµ÷º¯Êý
function chuli(){

//window.alert("»Øµ÷º¯Êý³É¹¦!!"+xmlHttpRequest.readyState); //»¹ÊÇÈ¡ÖµÁË if(xmlHttpRequest.readyState==4){ //window.alert("·þÎñÆ÷·µ»Ø"+xmlHttpRequest.responseText); $("myres").value=xmlHttpRequest.responseText; }

}
//ÕâÀïдһ¸öº¯Êý
function $(id){
return document.getElementById(id);
}
</script>
</head>
<body>
<form action="" method="post">
Óû§Ãû×Ö1£º<input type="text" onblur="checkName()" name="username1" id="username" />
Óû§Ãû×Ö£º<input type="text" onkeyup="checkName()" name="username2" id="username" />
<input onclick="checkName();" type="button" value="ÑéÖ¤Óû§Ãû" /><input style="border-width:0px;color:red;" type="text" id="myres"/> <br />
Óû§ÃÜÂ룺<input type="password" name="password" /> <br />
µç×ÓÓʼþ£º<input type="text" name="email" /> <br /> <input type="button" value="×¢²áÕ˺Å">
</form>
</body>
</html>

¶þ¡¢registerPro.php
<?php
$username = $_POST['username'];
// echo "Óû§ÃûÊÇ£º" . $username; // 3ºÅÏß
if ($username == "zhosoft") {
echo "´ËÓû§Ãû²»¿ÉÓã¡"; // ×¢Ò⣬ÕâÀïµÄÊý¾ÝÊÇ·µ»Ø¸øÇëÇóµÄÒ³Ãæ¡£
} else {
echo "¹§Ï²Äú£¬´ËÓû§Ãû¿ÉÓã¡";
}
?>

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • ³õʶAjax£¨Ò»£©

    ³õʶAjax£¨Ò»£©

    2017-11-12 13:00

  • jQueryÖÐajaxѧϰ¼Ç¼

    jQueryÖÐajaxѧϰ¼Ç¼

    2017-11-11 17:37

  • Ajax»ù´¡½Ì³ÌÔ´Âë

    Ajax»ù´¡½Ì³ÌÔ´Âë

    2017-11-11 13:08

  • »ùÓÚjqueryµÄ$.ajax asyncʹÓÃ

    »ùÓÚjqueryµÄ$.ajax asyncʹÓÃ

    2017-11-11 09:01

ÍøÓѵãÆÀ
±