<script type="text/javascript">
function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
}
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "gethint.php?q=" + str, true);
xmlhttp.send();
}
</script>
<form>
First name: <input type="text" onkeyup="showHint(this.value)" size="20" />
</form>
<span id="txtHint"></span>
-------------------------------------
<?php
$a[]="Anna";
$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[$a],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;
?>
내가
답변
내가 오류가 발생할 것이라고 생각
if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
여기 우승자가 있다고 생각하십시오! :) – epascarello
<form>
FirstN<input type="text" onkeyup="return showHint(this.value);" size="20" />
</form>
ok ... 감사합니다 ... – Partyboy
왜 그렇게해야합니까? 좋은 프로그래머라면 눈에 띄지 않게 추가 할 것이고, 이벤트 객체 자체를 통해 할 수있는 이벤트를 취소해야 할 필요가 없다면 return 문이 필요 없다. – epascarello
이 답변으로 마술처럼 포스터의 코드 작업이 이루어지지는 않을 것입니다. – epascarello
if (xmlhttp == 4 && xmlhttp.status == 200) {
Should BE
if (xmlhttp.readyState==4 && xmlhttp.status==200)
---------------------------
if (strtolower($q)==strtolower(substr($a[$a],0,strlen($q))))
Should BE
if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
이 줄
if (strtolower($q)==strtolower(substr($a[$a],0,strlen($q))))
을 변경해보십시오 텍스트 상자에 입력 할 때 내 아약스 전화가 작동하지 않습니다
strtolower(substr($a[$a],0,strlen($q))))
여기 $ a [$ a] .. 란 무엇입니까?
for($i=0; $i<count($a); $i++)
{
if (strtolower($q)==strtolower(substr($a[$a],0,strlen($q))))
는 $로 교체하십시오이
for($i=0; $i<count($a); $i++)
{
if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
$ 같이 변경하십시오 그런 다음 루프 실행에처럼 난 후 단지 $ A [] 무엇을 작동하지
- 1. 내가
- 2. 내가
- 3. 내가
- 4. 내가
- 5. 내가
- 6. 내가
- 7. 내가
- 8. 내가
- 9. 내가 ++
- 10. 내가
- 11. 내가
- 12. 내가
- 13. 내가
- 14. 내가
- 15. 내가
- 16. 내가,
- 17. 내가
- 18. 내가
- 19. 내가
- 20. 내가
- 21. 내가
- 22. 내가
- 23. 내가 (! 내가 변경할 수) 객체가
- 24. 내가 propperly 내가 오류를 이해할 수
- 25. 은, 어떻게 내가 내가 할 경우, 객체
- 26. 내가 링크를 클릭하면 내가 prettyphoto jQuery 플러그인
- 27. PHP/MySQL을 (내가) 내가 다양한 소스를 읽은
- 28. 어떻게 내가
- 29. 내가 JNA
- 30. 내가 클래스가
을하고있다? Fiddler 또는 Firebug를 보면 Ajax 호출이 서버로 연결되는 것을 볼 수 있습니까? 콘솔에 오류가 표시됩니까? – epascarello
서버 또는 클라이언트에서 오류가 있습니까? 브라우저에서 Ajax 호출을 직접하고 있다는 URL을 호출하는 것에 지쳤습니까? 그게 효과가 있니? 그것이 속보하고있는 지점을 찾아야합니다. – epascarello
파이어 버그의 호출 및 응답을 확인하십시오. 코드는 정상입니다. – booota