Jump to content

Ajax Live Search Help


wgcdesigns

Recommended Posts

Hi, Im trying to install Ajax live search found here originally:http://www.w3schools.com/php/php_ajax_livesearch.aspBut my test page is located at:http://wgcdesigns.com/clients/RH-Thackston-9-2009/When i run the code all i see is a gray line that appears under the text box where the suggestions should be. I think it has something to do with my livesearch.php page located at:http://wgcdesigns.com/clients/RH-Thackston.../livesearch.phpwhich does nothing when you try and visit.Anyone seen this and know a solution?Thanks!

Link to comment
Share on other sites

You are not testing your request object's status code, so you don't know if any errors occured on the server side. Seems like one does occur. The line appears because you give the div a border when the readyState hits 4. You were expecting characters to appear, but since there is an error, there is no response text. So you have a div with no defined height, and no content, so its height is zero, making the border look like a line.Your php script needs debugging, is the main thing. You probably have a syntax error and your error reporting is switched off. That leads to no responseText every time.

Link to comment
Share on other sites

Here is the code for the php page.---------------<?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

No. The box already has a fixed width. Only the border changes.
By 'Only the border changes.' do you mean that the height changes, cause if you have 5 suggestions and you never changed it from 0px. That can be a problem.
Link to comment
Share on other sites

By 'Only the border changes.' do you mean that the height changes, cause if you have 5 suggestions and you never changed it from 0px. That can be a problem.
If i add height to the css it makes the box grow to 200 but there still is nothing inside. Any other suggestions?------------<html><head><script type="text/javascript" src="livesearch.js"></script><style type="text/css">#livesearch { margin:0px; width:194px; height:200px; }#txt1 { margin:5px; }</style></head><body><form><input type="text" id="txt1" size="30" onKeyUp="showResult(this.value)" /><div id="livesearch"></div></form></body></html>
Link to comment
Share on other sites

I think the HTML is okay. If you don't trust it, test your PHP script from your address bar -- just pass your GET values in a ?query string. You might want to test the PHP that way anyway. It might be more efficient.And since it is a GET, keep sending different values in the query string so you don't keep getting a cached error response that isn't real.I don't see anything obviously wrong with the PHP. All the braces line up, etc. You can easily test for a parsing error by putting an echo statement at the top of the script and see if it echos. If it does, your syntax is okay. The logic could still be weird, but you'd know it's technically okay.If that's the case, add these two lines to the top of your script to temporarily engage error reporting. It should shed some light.error_reporting(E_ALL);ini_set('display_errors', 1);I suspect you may have a DOM error of some kind, like maybe your arrows don't point to the right things. Could be your XML doc has an error in it. If this problem drags on, you may want to post that to us also.

Link to comment
Share on other sites

Ok so i added those lines to the top and don't see any error messages, even when i submit a querystring nothing from the livesearch.php page.I entered:http://wgcdesigns.com/clients/RH-Thackston...earch.php?q=cssHere is my code for the xml sample page:http://wgcdesigns.com/clients/RH-Thackston-9-2009/links.xml---------<?xml version="1.0" encoding="ISO-8859-1"?><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

Something funny going on here! I copied all your files, and everything runs exactly as it should. Everything. I didn't change a line. Strictly copy and paste.The script runs correctly just from the address bar, and from your form.Two questions. (1) Is your XML doc where it's supposed to be? (2) Are you sure your implementation of PHP has support for DOM documents?As an experiment, add these lines after $xmlDoc->load()var_dump($xmlDoc);exit;What comes back to me is this: object(DOMDocument)#1 (0) { }If you don't get something kinda like that, your doc isn't loading for some reason.

Link to comment
Share on other sites

Something funny going on here! I copied all your files, and everything runs exactly as it should. Everything. I didn't change a line. Strictly copy and paste.The script runs correctly just from the address bar, and from your form.Two questions. (1) Is your XML doc where it's supposed to be? (2) Are you sure your implementation of PHP has support for DOM documents?As an experiment, add these lines after $xmlDoc->load()var_dump($xmlDoc);exit;What comes back to me is this: object(DOMDocument)#1 (0) { }If you don't get something kinda like that, your doc isn't loading for some reason.
The links.xml file is located in the same directory as the other files, no directory used.2nd I added that line of code to the livesearch.php page and nothing.. Looks like im running version PHP Version 4.3.1Do you need 5 to do DOM?
Link to comment
Share on other sites

That's a pretty old version. I don't know if DOM was available. If it was, it might not be part of the default installation.What you need is a test script, with just one statement in it:phpinfo();This will generate a report of ALL the bells and whistles in your setup. Scroll down to DOM. All the headers are alphabetical. If it's there, you're good. I'm thinking it might not be there. If not, scroll down till you find SimpleXML. If it's there, you should still be able to do what you need. If not . . .If worse comes to worst, someone out there probably has a class that parses XML.

Link to comment
Share on other sites

That's a pretty old version. I don't know if DOM was available. If it was, it might not be part of the default installation.What you need is a test script, with just one statement in it:phpinfo();This will generate a report of ALL the bells and whistles in your setup. Scroll down to DOM. All the headers are alphabetical. If it's there, you're good. I'm thinking it might not be there. If not, scroll down till you find SimpleXML. If it's there, you should still be able to do what you need. If not . . .If worse comes to worst, someone out there probably has a class that parses XML.
Thank you for the great info, i ran the report and im assuming its off which is the issue here?---comDirective Local Value Master Valuecom.allow_dcom Off Offcom.autoregister_casesensitive On Oncom.autoregister_typelib Off Offcom.autoregister_verbose Off Offcom.typelib_file no value no value
Link to comment
Share on other sites

I think your server needs to be reinstalled. Some hosts are lazy about upgrades; you have to push them or threaten to leave. If it's yours, then the job is yours. Someone else might have some info on that.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...