views:

139

answers:

2

The jQuery Autocomplete plugin relies on an odd response format. Specifically, it's a newline-separated list of pipe-delimited pairs, the first entry of each pair being some formatted text, the latter being a JSON object with some data.

An example:

Fuzzy Bunnies|{ id: '1234-fuzzy-bunnies', type: 'slippers' }
Loud Hawaiian Shirt|{ id: '3993-loud-hawaiian-shirt', type: 'shirt', sizes: ['S', 'M', 'L'] }

My question is: what sort of MIME type makes sense for this? It's not exactly application/json because of that odd pipe and the fact that the list is newline-delimited, not expresses as a Javascript array. Nor is it text/plain since only the first part is plain text (and even that might allow markup -- I'm not sure).

+3  A: 

You should send it as text/plain, because that is what it really is. The fact that some part of that text has a specific meaning, doesn't mean that the file is json.

Otherwise, for example, you could argue that a binary file storing a single text variable is a text file.

If you send that file as json you could have some problems, as is not a valid json file.

voyager
+1. You could also send it (or anything) as application/octet-stream to be completely non-specific about what type it is. However, browsers will always attempt to decode the bytes into a Unicode string in resposneText (defaulting to using UTF-8).
bobince
A: 

Content-Type: application/json; charset=iso-8859-1

andres descalzo