星空网 > 软件开发 > Java

ajax 向php发送请求

[html] view plaincopy

  1. <html>  
  2. <head>  
  3. <script src='/images/loading.gif' data-original="clienthint.js"></script>   
  4. </head>  
  5.   
  6. <body>  
  7.   
  8. <form>   
  9. First Name:  
  10. <input type="text" id="txt1"  
  11. onkeyup="showHint(this.value)">  
  12. </form>  
  13.   
  14. <p>Suggestions: <span id="txtHint"></span></p>  
  15.   
  16. </body>  
  17. </html>  


[html] view plaincopy

  1. clienthint.js  

[javascript] view plaincopy

  1. var 
  2.   
  3. function showHint(str)  
  4. {  
  5. if (str.length==0)  
  6.   {   
  7.   document.getElementById("txtHint").innerHTML=""  
  8.   return  
  9.   }  
  10. if (null)  
  11.   {  
  12.   alert ("Browser does not support HTTP Request")  
  13.   return  
  14.   }   
  15. var url="gethint.php"  
  16. url=url+"?q="+str  
  17. url=url+"&sid="+Math.random()  
  18. "GET",url,true)  
  19. null)  
  20. }   
  21.   
  22. function stateChanged()   
  23. {   
  24. if ("complete")  
  25.  {   
  26.  document.getElementById("txtHint").innerHTML=
  27.  }   
  28. }  
  29.   
  30. function Get
  31. {  
  32. var null;  
  33. try  
  34.  {  
  35.  // Firefox, Opera 8.0+, Safari  
  36.  new 
  37.  }  
  38. catch (e)  
  39.  {  
  40.  // Internet Explorer  
  41.  try  
  42.   {  
  43.   new ActiveXObject("Ms
  44.   }  
  45.  catch (e)  
  46.   {  
  47.   new ActiveXObject("Microsoft.
  48.   }  
  49.  }  
  50. return 
  51. }  

gethint.php

[php] view plaincopy

    1. <?php  
    2. // Fill up array with names  
    3. $a[]="Anna";  
    4. $a[]="Brittany";  
    5. $a[]="Cinderella";  
    6. $a[]="Diana";  
    7. $a[]="Eva";  
    8. $a[]="Fiona";  
    9. $a[]="Gunda";  
    10. $a[]="Hege";  
    11. $a[]="Inga";  
    12. $a[]="Johanna";  
    13. $a[]="Kitty";  
    14. $a[]="Linda";  
    15. $a[]="Nina";  
    16. $a[]="Ophelia";  
    17. $a[]="Petunia";  
    18. $a[]="Amanda";  
    19. $a[]="Raquel";  
    20. $a[]="Cindy";  
    21. $a[]="Doris";  
    22. $a[]="Eve";  
    23. $a[]="Evita";  
    24. $a[]="Sunniva";  
    25. $a[]="Tove";  
    26. $a[]="Unni";  
    27. $a[]="Violet";  
    28. $a[]="Liza";  
    29. $a[]="Elizabeth";  
    30. $a[]="Ellen";  
    31. $a[]="Wenche";  
    32. $a[]="Vicky";  
    33.   
    34. //get the q parameter from URL  
    35. $q=$_GET["q"];  
    36.   
    37. //lookup all hints from array if length of q>0  
    38. if (strlen($q) > 0)  
    39. {  
    40. $hint="";  
    41. for($i=0; $i<count($a); $i++)  
    42.   {  
    43.   if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))  
    44.     {  
    45.     if ($hint=="")  
    46.       {  
    47.       $hint=$a[$i];  
    48.       }  
    49.     else  
    50.       {  
    51.       $hint=$hint." , ".$a[$i];  
    52.       }  
    53.     }  
    54.   }  
    55. }  
    56.   
    57. //Set output to "no suggestion" if no hint were found  
    58. //or to the correct values  
    59. if ($hint == "")  
    60. {  
    61. $response="no suggestion";  
    62. }  
    63. else  
    64. {  
    65. $response=$hint;  
    66. }  
    67.   
    68. //output the response  
    69. echo $response;  
    70. ?> 




原标题:ajax 向php发送请求

关键词:ajax

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

汇通达:https://www.ikjzd.com/w/1758
祝佩_wish初级讲师:https://www.ikjzd.com/w/1759
Jungle Scout的功能介绍,支持站点,费用:https://www.ikjzd.com/w/176
有种网_农业商城:https://www.ikjzd.com/w/1760
夏启锋_wish讲师:https://www.ikjzd.com/w/1761
环球市场:https://www.ikjzd.com/w/1762
活动回顾 | 千亚麦佳携手MoonSees呈现精彩亚马逊运营管理课程:https://www.kjdsnews.com/a/1836386.html
生日景点免费 上海景点生日免费景点:https://www.vstour.cn/a/363173.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流