用户登录
用户注册

分享至

AJAX 实时读取输入文本(php)

  • 作者: 优柔寡断你二舅
  • 来源: 51数据库
  • 2021-08-21
客户端代码:
复制代码 代码如下:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.51sjk.com/Upload/Articles/1/0/270/270311_20210708032810246.jpg">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script language="javascript">
var xmlhttp;

function createxmlhttprequest(){
if(window.activexobject){
xmlhttp = new activexobject("microsoft.xmlhttp");
}
else if(window.xmlhttprequest){
xmlhttp = new xmlhttprequest();
}

}

function sendrequest(){

createxmlhttprequest();

var name = document.getelementbyid("name").value;
url = "string_check.php?page="+name;
xmlhttp.onreadystatechange = callback;
xmlhttp.open('get',url,true);
xmlhttp.send(null);
}

function callback(){
if(xmlhttp.readystate == 4){
if(xmlhttp.status == 200){
document.getelementbyid("show").innerhtml = "您输入的字符串为:"+ xmlhttp.responsetext;

}
}
}

</script>
<body>
<p>ajax test;</p>
<p><br/>
<input type="text" id="name" onkeyup="sendrequest();" />
<br/>
<span id="show"></span>
</p>
</body>
</html>


服务器端代码:
复制代码 代码如下:

<?php
header('content-type: text/html;charset=utf-8');
$ename = $_get["page"];
if ($ename == "") {
$ename = "请输入:";
}
echo ($ename);
exit(0);
?>
软件
前端设计
程序设计
Java相关