dileepd26 Posted September 10, 2010 Share Posted September 10, 2010 Hi Friends,I am Dileep, from B'lore. I tried to use the code from..http://www.w3schools.com/php/php_ajax_livesearch.aspThis code is working fine when i checked it offline, i created 3 files namely ajaxlivesearch.htm, livesearch.php, links.xml. I published the same code online no results are shown.I appreciate any positive response to solve this problem.Thanks.--------<html><head><script type="text/javascript">function showResult(str){if (str.length==0) { document.getElementById("livesearch").innerHTML=""; document.getElementById("livesearch").style.border="0px"; 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("livesearch").innerHTML=xmlhttp.responseText; document.getElementById("livesearch").style.border="1px solid #A5ACB2"; } }xmlhttp.open("GET","livesearch.php?q="+str,true);xmlhttp.send();}</script></head><body><form><input type="text" size="30" onkeyup="showResult(this.value)" /><div id="livesearch"></div></form></body></html>------------------<?php$xmlDoc=new DOMDocument();$xmlDoc->load("links.xml");$x=$xmlDoc->getElementsByTagName('link');//get the q parameter from URL$q=$_GET["q"];//lookup all links from the xml file if length of q>0if (strlen($q)>0){$hint="";for($i=0; $i<($x->length); $i++) { $y=$x->item($i)->getElementsByTagName('title'); $z=$x->item($i)->getElementsByTagName('url'); if ($y->item(0)->nodeType==1) { //find a link matching the search text if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) { if ($hint=="") { $hint="<a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } else { $hint=$hint . "<br /><a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } } } }}// Set output to "no suggestion" if no hint were found// or to the correct valuesif ($hint=="") { $response="no suggestion"; }else { $response=$hint; }//output the responseecho $response;?> Link to comment Share on other sites More sharing options...
justsomeguy Posted September 10, 2010 Share Posted September 10, 2010 Is your server running PHP? Are you getting any Javascript errors? Link to comment Share on other sites More sharing options...
dileepd26 Posted September 15, 2010 Author Share Posted September 15, 2010 Respected Sir,I am happy to hear from you, Yes my server running PHP, i could run other php files there.NO Javascript errors, Kindly check this linkhttp://www.ambtion.com/0/search.phpthis should get original results as in w3schools.comhttp://www.w3schools.com/php/php_ajax_livesearch.aspThanking you, Dileep Kumar. D Is your server running PHP? Are you getting any Javascript errors? Link to comment Share on other sites More sharing options...
justsomeguy Posted September 15, 2010 Share Posted September 15, 2010 Add this code to the top of your PHP file: ini_set('log_errors', 1);ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');ini_set('html_errors', 0);ini_set('display_errors', 0);error_reporting(E_ALL); That will send all PHP errors to a file called error.log in the same directory as the PHP script. There might be PHP errors that you just aren't seeing, using that code will send the errors to a log file that you can check later. Link to comment Share on other sites More sharing options...
dileepd26 Posted September 16, 2010 Author Share Posted September 16, 2010 Sir,As you informed i tried to upload php file with the code to check error. <?phpini_set('log_errors', 1);ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');ini_set('html_errors', 0);ini_set('display_errors', 0);error_reporting(E_ALL);$xmlDoc=new DOMDocument();$xmlDoc->load("links.xml");$x=$xmlDoc->getElementsByTagName('link');//get the q parameter from URL$q=$_GET["q"];//lookup all links from the xml file if length of q>0if (strlen($q)>0){$hint="";for($i=0; $i<($x->length); $i++) { $y=$x->item($i)->getElementsByTagName('title'); $z=$x->item($i)->getElementsByTagName('url'); if ($y->item(0)->nodeType==1) { //find a link matching the search text if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) { if ($hint=="") { $hint="<a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } else { $hint=$hint . "<br /><a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } } } }}// Set output to "no suggestion" if no hint were found// or to the correct valuesif ($hint=="") { $response="no suggestion"; }else { $response=$hint; }//output the responseecho $response;?>___ Add this code to the top of your PHP file:ini_set('log_errors', 1);ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');ini_set('html_errors', 0);ini_set('display_errors', 0);error_reporting(E_ALL); That will send all PHP errors to a file called error.log in the same directory as the PHP script. There might be PHP errors that you just aren't seeing, using that code will send the errors to a log file that you can check later. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 16, 2010 Share Posted September 16, 2010 Sounds good. Check the error log and let me know how it turned out. Link to comment Share on other sites More sharing options...
dileepd26 Posted September 17, 2010 Author Share Posted September 17, 2010 Sir,I checked error log but no data in the log. 0 kb.If required i'll provide my ftp.ambtion.com ID & password so that you help me to make the coding work online.I would like to invite you to accept your new email idjustsomeguy@ambtion.comidjustsomeguy* is your pwd.Thanks. Sounds good. Check the error log and let me know how it turned out. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 17, 2010 Share Posted September 17, 2010 I'm not going to use that email address, but thanks anyway. I'm not here to fix your problems, I'm here to help you fix your problems.Create a file with this in it: <?phpini_set('display_errors', 1);error_reporting(E_ALL);include 'file.php';?> Replace the file.php filename there with the name of your actual PHP file. This is a file that turns on error messages and then includes your other file. Once you replace the filename and save that file on your server, open it in a browser. Don't use ajax, just type the URL of that PHP file into your browser and see what you get. Link to comment Share on other sites More sharing options...
dileepd26 Posted September 18, 2010 Author Share Posted September 18, 2010 Sir,I created errorcheck.php & put the code in it. I also replaced file.php with liveserch.phpWhen i checked for error after uploading it i got the following error. Parse error: parse error, unexpected T_OBJECT_OPERATOR in /0/livesearch.php on line 22 I'm not going to use that email address, but thanks anyway. I'm not here to fix your problems, I'm here to help you fix your problems.Create a file with this in it:<?phpini_set('display_errors', 1);error_reporting(E_ALL);include 'file.php';?> Replace the file.php filename there with the name of your actual PHP file. This is a file that turns on error messages and then includes your other file. Once you replace the filename and save that file on your server, open it in a browser. Don't use ajax, just type the URL of that PHP file into your browser and see what you get. Link to comment Share on other sites More sharing options...
Synook Posted September 18, 2010 Share Posted September 18, 2010 Well, what is on line 22? Does anything look wrong with it to you? Link to comment Share on other sites More sharing options...
dileepd26 Posted September 18, 2010 Author Share Posted September 18, 2010 Sir,On line 22 only: { symbol.livesearch.php contains <?php$xmlDoc=new DOMDocument();$xmlDoc->load("links.xml");$x=$xmlDoc->getElementsByTagName('link');//get the q parameter from URL$q=$_GET["q"];//lookup all links from the xml file if length of q>0if (strlen($q)>0){$hint="";for($i=0; $i<($x->length); $i++) { $y=$x->item($i)->getElementsByTagName('title'); $z=$x->item($i)->getElementsByTagName('url'); if ($y->item(0)->nodeType==1) { //find a link matching the search text if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) { if ($hint=="") { $hint="<a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } else { $hint=$hint . "<br /><a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } } } }}// Set output to "no suggestion" if no hint were found// or to the correct valuesif ($hint=="") { $response="no suggestion"; }else { $response=$hint; }//output the responseecho $response;?> Well, what is on line 22? Does anything look wrong with it to you? Link to comment Share on other sites More sharing options...
jeffman Posted September 18, 2010 Share Posted September 18, 2010 My server parses that code with no errors. Link to comment Share on other sites More sharing options...
HungryMind Posted September 18, 2010 Share Posted September 18, 2010 Hi!I Tried This Example On My FTP Server.But It's Working Properly.If U Are Talking About Right This Example.But! I Got An Issue When I Tested First.First Time Result Was Show Little More Late.Then Second Time.It Was OK.U Can Check Yourself.Lesson 5 Ajax W3Schools Example Link to comment Share on other sites More sharing options...
dsonesuk Posted September 18, 2010 Share Posted September 18, 2010 your link is showing errorsError: uncaught exception: [Exception... "Not enough arguments" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: http://www.ambtion.com/0/search.php :: showResult :: line 29" data: no]which is xmlhttp.send();try adding null to xmlhttp.send();xmlhttp.send(null); Link to comment Share on other sites More sharing options...
dileepd26 Posted September 18, 2010 Author Share Posted September 18, 2010 Sir,It is different, That code is also working at my domain, but it'll list result in text format only.i need the results in html format as links,Check the link below.http://www.w3schools.com/php/php_ajax_livesearch.asp Hi!I Tried This Example On My FTP Server.But It's Working Properly. Link to comment Share on other sites More sharing options...
dsonesuk Posted September 18, 2010 Share Posted September 18, 2010 OK the reason its not working is you need version 5 of PHP.either rename extensions to php5orInserted a .htaccess file within directory withAddType x-mapp-php5 .phpthen it will run fine. Link to comment Share on other sites More sharing options...
HungryMind Posted September 18, 2010 Share Posted September 18, 2010 Hi!But My Friend My CODE & Your CODE Is Same.But Mine Is Working On My FTP...Ok Im Pasting Here My CODE.U Try Or U Can Downloadindex.htm <html><head><script src="livesearch.js"></script> <style type="text/css"> #livesearch { margin:0px; width:194px; }#txt1 { margin:0px; } </style></head><body><form><input type="text" id="txt1" size="30" onkeyup="showResult(this.value)"><div id="livesearch"></div></form></body></html> livesearch.php <?php$xmlDoc = new DOMDocument();$xmlDoc->load("links.xml");$x=$xmlDoc->getElementsByTagName('link');//get the q parameter from URL$q=$_GET["q"];//lookup all links from the xml file if length of q>0if (strlen($q) > 0){$hint="";for($i=0; $i<($x->length); $i++) { $y=$x->item($i)->getElementsByTagName('title'); $z=$x->item($i)->getElementsByTagName('url'); if ($y->item(0)->nodeType==1) { //find a link matching the search text if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) { if ($hint=="") { $hint="<a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } else { $hint=$hint . "<br /><a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } } } }}// Set output to "no suggestion" if no hint were found// or to the correct valuesif ($hint == "") { $response="no suggestion"; }else { $response=$hint; }//output the responseecho $response;?> livesearch.js var xmlHttpfunction showResult(str){if (str.length==0) { document.getElementById("livesearch"). innerHTML=""; document.getElementById("livesearch"). style.border="0px"; return }xmlHttp=GetXmlHttpObject()if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="livesearch.php"url=url+"?q="+strurl=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("livesearch"). innerHTML=xmlHttp.responseText; document.getElementById("livesearch"). style.border="1px solid #A5ACB2"; } }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;} links.xml <?xml version="1.0" encoding="utf-8"?><pages><link><title>HTML DOM alt Property</title><url>http://www.w3schools.com/htmldom/prop_img_alt.asp</url></link><link><title>HTML DOM height Property</title><url>http://www.w3schools.com/htmldom/prop_img_height.asp</url></link><link><title>HTML a tag</title><url>http://www.w3schools.com/tags/tag_a.asp</url></link><link><title>HTML br tag</title><url>http://www.w3schools.com/tags/tag_br.asp</url></link><link><title>CSS background Property</title><url>http://www.w3schools.com/css/pr_background.asp</url></link><link><title>CSS border Property</title><url>http://www.w3schools.com/css/pr_border.asp</url></link><link><title>JavaScript Date() Method</title><url>http://www.w3schools.com/jsref/jsref_date.asp</url></link><link><title>JavaScript anchor() Method</title><url>http://www.w3schools.com/jsref/jsref_anchor.asp</url></link></pages> Link to comment Share on other sites More sharing options...
dileepd26 Posted September 18, 2010 Author Share Posted September 18, 2010 Sir,I changed it as you informed to to null but no results. It only works offline not online. xmlhttp.send(null); your link is showing errorsError: uncaught exception: [Exception... "Not enough arguments" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: http://www.ambtion.com/0/search.php :: showResult :: line 29" data: no]which is xmlhttp.send();try adding null to xmlhttp.send();xmlhttp.send(null); Link to comment Share on other sites More sharing options...
dsonesuk Posted September 18, 2010 Share Posted September 18, 2010 check last post #16HOPEFULLY your server runs php5 Link to comment Share on other sites More sharing options...
jeffman Posted September 18, 2010 Share Posted September 18, 2010 The site seems to work for me. I get no error messages, and when I type characters, a menu of suggestions appears. This is the correct URL? http://www.muhammadsameer.com/projects/ajax/Lesson5/ Link to comment Share on other sites More sharing options...
dsonesuk Posted September 18, 2010 Share Posted September 18, 2010 thats a link to hungrymind page, you want to go to http://www.ambtion.com/0/search.php Link to comment Share on other sites More sharing options...
jeffman Posted September 18, 2010 Share Posted September 18, 2010 Ah, yes. Since the script expects GET data, I sent a direct request to livesearch.php with a query string. Blank response. Link to comment Share on other sites More sharing options...
MrFish Posted September 20, 2010 Share Posted September 20, 2010 It works for me as well. What browser are you using?Edit: Oh I see. This is copied entirely from w3c huh Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.