Ajax 实现

前端之家收集整理的这篇文章主要介绍了Ajax 实现前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<html>
	<head>
	<title>hello ajax</title>
	<script>
	var xmlRequest=null;
	function hint(content)
	{
		
		if(window.XMLHttpRequest)
		{
			xmlRequest=new XMLHttpRequest();	
		}
		else if(window.ActiveXObject)
		{
			xmlRequest=new ActiveXObject("Microsoft.XMLHTTP");
		}
		var url="helloAjax.PHP?name="+content+"&q="+Math.random();
		
		xmlRequest.onreadystatechange=stateChanged ;
		xmlRequest.open("GET",url,true);
		xmlRequest.send(null);	
	}
	function stateChanged() 
	{
		if (xmlRequest.readyState==4 || xmlRequest.readyState=="complete")
	 	{ 
 		document.getElementById("targetDiv").innerHTML=xmlRequest.responseText;
 		} 
	}
	</script>
	</head>

	<body>
		
		hello ajax:<input type="text" id="inputField" name="txt" onkeyup="hint(this.value)">
		<div id="targetDiv"></div>
	</body>
</html>

helloAjax.PHP

<?PHP
	echo $_GET["name"];
?>

猜你在找的Ajax相关文章