简体   繁体   中英

Javascript autocomplete using Jquery - problem

I am trying to use the autocomplete script on http://www.devbridge.com/projects/autocomplete/jquery/ .

Now, the downloaded code did not have the callback script. I made my own PHP script - that did not work. I am trying to use devbridge's serviceUrl (absolute), but that too does not work. The local version (months) on the site is working on my site too. But the one with callback does not work.

Here are the steps I tried:

I) Downloaded http://www.devbridge.com/projects/autocomplete/jquery/ directory.

II) 1) Approach one: I changed serviceUrl line in index.html to:

serviceUrl: 'http://www.devbridge.com/projects/autocomplete/service/autocomplete.ashx',

Still, only the local version of autocomplete works.

(The serviceUrl seems to be working fine - try http://www.devbridge.com/projects/autocomplete/service/autocomplete.ashx?query=a in the browser.

2) Approach two: I tried writing my own autocomplete.php, but that did not work either:

<?php

$temp=$_GET["query"];

 // Return some dummy data that matches the format.
 //json_encode introduces extra quotes ", so I decided to manually format the result

$result="{ query:'$temp',suggestions:['${temp}beria','${temp}byan Arab Jamahiriya','${temp}echtenstein','${temp}thuania'],data:['${temp}lr,'${temp}ly,'${temp}li,'${temp}lt] }";

header('Content-type: application/json');

echo $result;
?>

I checked that on every key press, correct requests are being made to autocomplete.php on my server. (And "seemingly", the php script is giving correct output). But the autocomplete does not work.

Any pointers on how to debug? Am I missing some files/modules etc?

regards,

JP

Does the page compile? If not I found this error checker script pretty helpful.

    <?php


ini_set('display_errors','1');
ini_set('display_startup_errors','1');
error_reporting (E_ALL|E_WARNING|E_PARSE);

include('filename.php');
?> 

Maybe it will help.

In case someone finds this useful:

I have started using the solution on code.google.com ( http://code.google.com/p/jquery-autocomplete/ )

It is very light weight and easy to use. It had a minor bug (list not getting erased if you erase the whole text). Fixed it by adding 8-10 lines of extra code.

You can download the file from here:

https://sites.google.com/site/janakporwal/home/javascript-auto-complete

(direct link: https://sites.google.com/site/janakporwal/home/javascript-auto-complete/jquery.autocomplete.js?attredirects=0&d=1 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM