Jump to content

Php Example - Ajax Live Search


Guest kevparky

Recommended Posts

Guest kevparky

HiI've used the PHP Example - AJAX Live Search example featured here and think its brilliant.My question is, when one of the links is clicked is it possible to not only take the user to the url (in the xml file) but also populate a box on the form with the results e.g.

<link><title>Leaflet 223</title> --- (to populate the editbox etc)<url>./Leaflets/leaflet223.html</url> --- (the link to the file)</link>

I've tried using $response and $hint to populate the box but I guess it would have to capture the contents as the click occurs to maintain a single result rather than all matching results.Any help would be appreciated.ThanksKevparky

Link to comment
Share on other sites

The code like they give it doesn't really support that, the PHP script just returns some text and the Javascript shows that text. If you want more features then that, then the PHP script needs a way to return more than one piece of information. One way to do that is to return some data in JSON format. PHP could return this text:{"title":"Leaflet 223","url":"./Leaflets/leaflet223.html"}That's a Javascript object. So the Javascript code would need to be changed to turn that text into an object and then it would have access to the title and url properties.

function stateChanged(){  if (xmlhttp.readyState==4)  {	var obj = eval('(' + xmlhttp.responseText + ')');	alert(obj.title);	alert(obj.url);	document.getElementById("livesearch").innerHTML=obj.title;	document.getElementById("livesearch").style.border="1px solid #A5ACB2";  }}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...