首页
Web开发
Windows程序
编程语言
数据库
移动开发
系统相关
微信
其他好文
会员
首页
>
Web开发
> 详细
ajax 向php发送请求
时间:
2015-06-27 18:08:07
阅读:
247
评论:
0
收藏:
0
[点我收藏+]
标签:
[html]
view plain
copy
<
html
>
<
head
>
<
script
src=
"clienthint.js"
>
</
script
>
</
head
>
<
body
>
<
form
>
First Name:
<
input
type=
"text"
id=
"txt1"
onkeyup=
"showHint(this.value)"
>
</
form
>
<
p
>Suggestions:
<
span
id=
"txtHint"
>
</
span
>
</
p
>
</
body
>
</
html
>
[html]
view plain
copy
clienthint.js
[javascript]
view plain
copy
var xmlHttp
function showHint(str)
{
if (str.length==0)
{
document.getElementById(
"txtHint").innerHTML=
""
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==
null)
{
alert (
"Browser does not support HTTP Request")
return
}
var url=
"gethint.php"
url=url+
"?q="+str
url=url+
"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open(
"GET",url,
true)
xmlHttp.send(
null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState==
"complete")
{
document.getElementById(
"txtHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=
null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=
new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=
new ActiveXObject(
"Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=
new ActiveXObject(
"Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
gethint.php
[php]
view plain
copy
<?php
// Fill up array with names
$a[]=
"Anna";
$a[]=
"Brittany";
$a[]=
"Cinderella";
$a[]=
"Diana";
$a[]=
"Eva";
$a[]=
"Fiona";
$a[]=
"Gunda";
$a[]=
"Hege";
$a[]=
"Inga";
$a[]=
"Johanna";
$a[]=
"Kitty";
$a[]=
"Linda";
$a[]=
"Nina";
$a[]=
"Ophelia";
$a[]=
"Petunia";
$a[]=
"Amanda";
$a[]=
"Raquel";
$a[]=
"Cindy";
$a[]=
"Doris";
$a[]=
"Eve";
$a[]=
"Evita";
$a[]=
"Sunniva";
$a[]=
"Tove";
$a[]=
"Unni";
$a[]=
"Violet";
$a[]=
"Liza";
$a[]=
"Elizabeth";
$a[]=
"Ellen";
$a[]=
"Wenche";
$a[]=
"Vicky";
//get the q parameter from URL
$q=
$_GET[
"q"];
//lookup all hints from array if length of q>0
if (
strlen(
$q) > 0)
{
$hint=
"";
for(
$i=0;
$i<
count(
$a);
$i++)
{
if (
strtolower(
$q)==
strtolower(
substr(
$a[
$i],0,
strlen(
$q))))
{
if (
$hint==
"")
{
$hint=
$a[
$i];
}
else
{
$hint=
$hint.
" , ".
$a[
$i];
}
}
}
}
//Set output to "no suggestion" if no hint were found
//or to the correct values
if (
$hint ==
"")
{
$response=
"no suggestion";
}
else
{
$response=
$hint;
}
//output the response
echo
$response;
?>
ajax 向php发送请求
标签:
原文地址:http://www.cnblogs.com/Lance--blog/p/4604214.html
踩
(
0
)
赞
(
0
)
举报
评论
一句话评论(
0
)
登录后才能评论!
分享档案
更多>
2021年07月29日 (22)
2021年07月28日 (40)
2021年07月27日 (32)
2021年07月26日 (79)
2021年07月23日 (29)
2021年07月22日 (30)
2021年07月21日 (42)
2021年07月20日 (16)
2021年07月19日 (90)
2021年07月16日 (35)
周排行
更多
36.VUE — 认识 Webpack 和 安装
2021-07-28
【PHP】上传图片翻转问题
2021-07-28
php对数字进行万。亿的转化
2021-07-28
五个 .NET 性能小贴士
2021-07-28
Three.js中显示坐标轴、平面、球体、四方体
2021-07-28
.net 5+ 知新:【1】 .Net 5 基本概念和开发环境搭建
2021-07-27
1.html,css
2021-07-27
基于Docker搭建 Php-fpm + Nginx 环境
2021-07-27
nginx + http + svn
2021-07-27
kubernets kube-proxy的代理 iptables和ipvs
2021-07-26
友情链接
兰亭集智
国之画
百度统计
站长统计
阿里云
chrome插件
新版天听网
关于我们
-
联系我们
-
留言反馈
© 2014
mamicode.com
版权所有 联系我们:gaon5@hotmail.com
迷上了代码!