0

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);
        // 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>

<script>

I have no idea why it would completely ignore the .php file specified in the serviceURL. I have no idea why it would return self.

Hitting return in the text input field would post to the same page, so I tried to disable submit by returning false in the form definition. Didn’t help. The form this text input was defined in wasn’t really necessary so I turned it into a div so the form wouldn’t default to self. Didn’t help. Still just returns script section of current page. Tried in Firefox and then Safari Developer Edition, since it seemed like it might be a bug. Same behavior in both.

The project is huge so I can’t really reproduce it here in a small form. I need an idea of what to try next… Just some direction…

0

Browse other questions tagged or ask your own question.