1

im using jquery-autocomplete (http://code.google.com/p/jquery-autocomplete)

what i don't understand is how to parse a complex json object to it. So far with "remoteDataType: 'json'" all i can specify is a "name" and "value".

But i want to pass in a large json object "data" with other fields such as

name: Mr Smith, address: 180 my road, value: 12345

so it seems to understand a name and value as a key-val. But how do i get address in the showResult or onItemSelect functions?

Thanks

1 Answer 1

1

I have no problems with serving JSON responses like this:

[
    {
        value: 'Mr Smith, 180 My Rd, 12345',
        data: {
            name: 'Mr Smith',
            address: '180 My Rd',
            value: '12345'
        }
    },
    ...
]

The catch is that if you use jQuery.ajax, then the interpretation of returned JSON changes depending on Content-Type header - if it's 'application/json' then you have to turn off "remoteDataType: 'json'", beacuse jQuery pre-parses JSON string and returns a Javacript object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.