単一のテキスト文字列を<input>
にバインドしようとしています。 RESTサービスは、JSONに埋め込まれた単純なテキスト文字列を返します。クライアントはテキスト文字列を取得しますが、私はparsererror
を取得します。 ajaxリクエストは失敗しますが、テキスト文字列jq.responseText
が含まれています。RESTサービスの値をバインドするときのパーサーエラーKnockoutJS
何が原因なのですか?また、RESTサービスから単一の文字列(配列ではない)値をバインドするにはどうすればよいですか?
PS。私は、KnouckoutJS、JQueryおよびその他のJSライブラリをベースとしたOracle Jetフレームワークを使用しています。
header.html
<input type='text' data-bind="value:hello" />
header.js
define(['ojs/ojcore', 'knockout' ], function (oj, ko) {
/**
* The view model for the main content view template
*/
function headerContentViewModel() {
var self = this;
self.hello = ko.observable("local hello");
this.getStatus = function() {
$.ajax({
dataType: 'json',
type: 'GET',
url: "http://localhost:8080/clear-obs/service/application/hello",
success: function (data) {
$.parseJSON(data);
self.hello(data.message);
},
error: function (jq, st, error) {
alert(jq.responseText);
}
});
};
self.getStatus();
}
return headerContentViewModel;
});
テキスト文字列
{
"message": "Hello World from REST service"
}
リクエストに 'dataType:" json "'を追加しようとしましたか? – user3297291
はい、同じエラーが発生します。 – Chris
クロムを使用している場合は、[ネットワーク]タブを開いてリクエストしてください。リクエストがこのタブに表示され、エラーがあれば赤色になります。その後、イベントをクリックすると詳細が表示されます。 –