narjis Posted April 7, 2011 Share Posted April 7, 2011 I've copied this exmaple form w3school website as it is but my browser does not display tghe correct result. Here's the code <html> <head> <script type="text/javascript"> function showHint(str) { var xmlhttp; 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.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","gethint.asp?q="+str,true); xmlhttp.send(); } </script> </head> <body> <h3>Start typing a name in the input field below:</h3> <form action=""> First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" /> </form> <p>Suggestions: <span id="txtHint"></span></p> </body> </html> Php code is as follows <?php $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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/233008-browser-not-displaying-anything/ Share on other sites More sharing options...
gizmola Posted April 7, 2011 Share Posted April 7, 2011 How would you expect this to work when it's calling an asp script and your serverside script is php? xmlhttp.open("GET","gethint.asp?q="+str,true); Quote Link to comment https://forums.phpfreaks.com/topic/233008-browser-not-displaying-anything/#findComment-1198376 Share on other sites More sharing options...
narjis Posted April 7, 2011 Author Share Posted April 7, 2011 still not working. Quote Link to comment https://forums.phpfreaks.com/topic/233008-browser-not-displaying-anything/#findComment-1198379 Share on other sites More sharing options...
gizmola Posted April 7, 2011 Share Posted April 7, 2011 Test this in firefox using firebug with the net tab open and see if your script is being called, and if a response is being returned. Quote Link to comment https://forums.phpfreaks.com/topic/233008-browser-not-displaying-anything/#findComment-1198383 Share on other sites More sharing options...
gizmola Posted April 7, 2011 Share Posted April 7, 2011 On other thing... if this is a real server, you're going to need an actual url to the script. This won't work: xmlhttp.open("GET","gethint.php?q="+str,true); Quote Link to comment https://forums.phpfreaks.com/topic/233008-browser-not-displaying-anything/#findComment-1198386 Share on other sites More sharing options...
narjis Posted April 7, 2011 Author Share Posted April 7, 2011 I'm working on localhost where can I find firebug. Thanks for helping. Quote Link to comment https://forums.phpfreaks.com/topic/233008-browser-not-displaying-anything/#findComment-1198388 Share on other sites More sharing options...
narjis Posted April 7, 2011 Author Share Posted April 7, 2011 Problem resolved. It's working now. Quote Link to comment https://forums.phpfreaks.com/topic/233008-browser-not-displaying-anything/#findComment-1198391 Share on other sites More sharing options...
gizmola Posted April 7, 2011 Share Posted April 7, 2011 I'm working on localhost where can I find firebug. Thanks for helping. Firebug is a plugin for firefox. If you're going to be working with ajax and complex javascript it's just about indespensible as a testing/debugging tool. Quote Link to comment https://forums.phpfreaks.com/topic/233008-browser-not-displaying-anything/#findComment-1198394 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.