亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2578 | 回復(fù): 1
打印 上一主題 下一主題

AJAX的post有問題,get沒問題。! [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2011-06-06 12:28 |只看該作者 |倒序?yàn)g覽
我測試了status和readyState的值都正常,納悶的是get方式傳值卻很正常,幫忙看看怎么回事?

有三個(gè)文件,如下:

1.text.php
  1. <html>
  2. <head>
  3. <script src="clienthint.js"></script>
  4. </head>
  5. <body>
  6. <form>
  7. First Name:
  8. <input type="text" id="txt1">
  9. <input type="button" value="Submit" onClick="showHint()">
  10. </form>
  11. <p>Suggestions: <span id="txtHint"></span></p>
  12. </body>
  13. </html>
復(fù)制代碼
2.clienthint.js
  1. var xmlHttp
  2. function showHint()
  3. {
  4. var str = document.getElementById("txt1").value;
  5. if (str.length==0)
  6.   {
  7.   document.getElementById("txtHint").innerHTML="";
  8.   return;
  9.   }
  10. xmlHttp=GetXmlHttpObject();
  11. if (xmlHttp==null)
  12.   {
  13.   alert ("Browser does not support HTTP Request");
  14.   return;
  15.   }
  16. var url="gethint.php";
  17. var content="qt="+str;
  18. content=content+"&sid="+Math.random();
  19. xmlHttp.open("POST",url,true);
  20. xmlHttp.onreadystatechange=stateChanged;
  21. xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  22. xmlHttp.send(content);
  23. }

  24. function stateChanged()
  25. {
  26. if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  27. {
  28. document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
  29. }
  30. }

  31. function GetXmlHttpObject()
  32. {
  33. var xmlHttp=null;
  34. try
  35. {
  36. // Firefox, Opera 8.0+, Safari
  37. xmlHttp=new XMLHttpRequest();
  38. }
  39. catch (e)
  40. {
  41. // Internet Explorer
  42. try
  43.   {
  44.   xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  45.   }
  46. catch (e)
  47.   {
  48.   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  49.   }
  50. }
  51. return xmlHttp;
  52. }
復(fù)制代碼
3.gethint.php
  1. <?php
  2. // Fill up array with names
  3. $a[]="Anna";
  4. $a[]="Brittany";

  5. $q = $_POST["qt"];
  6. if (strlen($q) > 0)
  7. {
  8. $hint="";
  9. for($i=0; $i<count($a); $i++)
  10.   {
  11.   if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
  12.     {
  13.     if ($hint=="")
  14.       {
  15.       $hint=$a[$i];
  16.       }
  17.     else
  18.       {
  19.       $hint=$hint." , ".$a[$i];
  20.       }
  21.     }
  22.   }
  23. }
  24. else echo "q is empty!<br>";
  25. //Set output to "no suggestion" if no hint were found
  26. //or to the correct values
  27. if ($hint == "")
  28. {
  29. $response="no suggestion";
  30. }
  31. else
  32. {
  33. $response=$hint;
  34. }

  35. //output the response
  36. echo $response;
  37. echo " to ";
  38. echo $q;
  39. echo "<br>";
  40. ?>
復(fù)制代碼

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2011-06-07 07:23 |只看該作者

沒人頂。。。。
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP