did not get JSON/AJAX working

felix's Avatar

felix

12 Apr, 2010 12:26 PM

Hi,

My html:
<script type="text/javascript">
$(function(){
$("#qinput").autoSuggest("http://my-domain/my-folder/index.php", {selectedItemProp: "name", searchObjProps: "name", startText: "", keyDelay: 50, minChars: 1});
});
</script>
</body>

My index.php:

<?PHP

$json = array();

$json['value'] = 1;
$json['name'] = "Anna";
$data[] = $json;

$json['value'] = 2;
$json['name'] = "Anne";
$data[] = $json;

header("Content-type: application/json");
echo json_encode($data);

?>

My JSON-Response:

[{"value":1,"name":"Anna"},{"value":2,"name":"Anne"}]

When typing, I only get "No results found". What am I doing wrong?

Thanks for help,
Felix

  1. 1 Posted by Markus on 13 Apr, 2010 01:46 PM

    Markus's Avatar

    Same here. :(

  2. 2 Posted by TarGZ on 14 Apr, 2010 09:56 AM

    TarGZ's Avatar

    My problem, too… O.o

  3. 3 Posted by Aaron on 26 Apr, 2010 02:45 AM

    Aaron's Avatar

    Having the same issue - and when I take the results of the ajax page and use them with AutoSuggest in non-ajax mode they work so I know the encoding is working properly.

  4. 4 Posted by nathan on 07 May, 2010 06:51 PM

    nathan's Avatar

    i swapped name + value and it worked. odd.

  5. 5 Posted by Aaron on 07 May, 2010 07:02 PM

    Aaron's Avatar

    This was my own stupid mistake - I was trying to hit a web service on a different domain to get my json data - it was a sandboxing issue.

  6. 6 Posted by Raju on 25 May, 2010 11:25 PM

    Raju's Avatar

    This might save someone a lot of time. I spent 1 hour debugging the issue to realise that its a simple issue with the default parameter. selectedValuesProp: "value", should be defined as "name". Currently in the script value is the default.

    Regards
    Raju

  7. 7 Posted by Raju on 25 May, 2010 11:29 PM

    Raju's Avatar

    sorry I posted the wrong value in the last message. Actually selectedItemProp has to be set to name and selectedValuesProp hat to be left as value.

    sorry for the confusion.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac