私はjson応答を次のようにフォーマットしようとしています:
[
{
"id": "23029",
"label": "F:\path\to\file\filename.txt",
"value": "filename.txt"
},
{
"id": "23030",
"label": "F:\path\to\file\filename.txt",
"value": "filename.txt"
},
{
"id": "23031",
"label": "F:\path\to\file\filename.txt",
"value": "filename.txt"
}
]
しかし、JSONLintによると、 \ は「構造」を壊していますか? \ を | に置き換えると それは動作するので、\ が問題であることはわかっています。jQuery の Autocompleteで応答を使用しています。
代わりに SerializeJSON() を使用する必要がありますか? もしそうなら、ajax オートコンプリート スクリプトで何かを変更する必要がありますか?
$(function() {
var cache = {},
lastXhr;
$( "#media" ).autocomplete({
minLength: 2,
source: function( request, response ) {
var term = request.term;
if ( term in cache ) {
response( cache[ term ] );
return;
}
lastXhr = $.getJSON( "ajax/search.cfm", request, function( data, status, xhr ) {
cache[ term ] = data;
if ( xhr === lastXhr ) {
response( data );
}
});
}
});
});