devbridge / jQuery-Autocomplete

Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
https://www.devbridge.com/sourcery/components/jquery-autocomplete/
Other
3.56k stars 1.66k forks source link

Autocomplete ignores serviceURL and returns “self” instead #854

Closed KenBotwinick closed 3 weeks ago

KenBotwinick commented 4 months ago

Trying to implement a simple devbridge autocomplete which uses a .php file to query MySQL:

$("#theories").devbridgeAutocomplete({ serviceURL: 'theorySearch.php', paramName: 'theories' });

Was constantly getting the following in the console when testing the text input field:

Uncaught SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

I had manually tested the .php file by accessing it directly with the query string in the URL and it returns exactly the right format expected, so it seemed autocomplete was getting the wrong response.

To better figure out what the problem was, I modified the autobridge .js to show the response in the console:

function _transformResult(response) { console.log(response); // added debugging // the following line is the parseJSON that returns the error return typeof response === 'string' ? $.parseJSON(response) : response; }

The response was the script section of the originating page where this is all defined:

`<!doctype html>

Githubissues.
  • Githubissues is a development platform for aggregating issues.