オートコンプリート機能のJSONをリクエストしています。残念ながら、JSONはhtmlスパンタグでラップされています。これは、VBで記述された貧弱なバックエンドライブラリのために発生します。これは、数ヶ月以内にオペレータによって変更されません。だから、別の方法でhtmlスパンタグを取り除かなければならない。私のJSコールとレスポンスは以下の通りです:jQuery JSONレスポンスがHTMLでラップされています
module.props.functions.ajaxSearchon = function (currVal) {
// Search on Type
$.ajax({
url: module.props.apiURLs.searchOnType + '?query=' + currVal + '&lang=' + module.props.lang,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
module.state = {
searchResult: result,
searchQuery: currVal
};
},
error: function (xhr, status, error) {
module.state = $.extend(module.state, {
searchResults: 'no results found'
});
console.log("error", module.state);
},
complete: function() {
module.props.functions.refreshSearchResults();
}
})
};
これは応答として整形式JSONで優れています。しかし、私の応答は次のようになります。だから、
<span id="fromContext">
{
"results": [
{
"headline": "headline text",
"summary": " <em>summary</em> result text",
"url": "/url/to/page",
"image": {
"url": "/media.jpg",
"alt": "media alt text"
},
"count": ""
},
{
"headline": "empty object"
}
],
"hasmore": true
}
</span>
(それはIDを持っているので)、私はスパンを検出することができるだろうが、私は、Ajaxリクエストに応答全体のJSONの一部にアクセスする方法を知りません。私は、この主な問題は、応答がJSONではないため、エラーでajax呼び出しが発生すると考えています... どのようにこの問題を解決するためのアイデア?