backbone.js エラーがあります:
キャッチされていない TypeError: {"websiteID":"2","title":"titre site 2"} backbone-min.js:9 で 'id' を検索するために 'in' 演算子を使用できません
json データ (ajax から受信) をモデルのインスタンスにコピーしようとしています。
この問題を解決するにはどうすればよいですか?
私のコードは次のとおりです。
var Website = Backbone.Model.extend({
// set default json data in the website:
defaults: {"websiteID":"1","title":"default title"}
});
var website = new Website();
function UpdateWebsiteBasedOnDBData() {
this.url = 'script.php';
}
UpdateWebsiteBasedOnDBData.prototype.readData = function(dataToGet) {
return $.ajax({
type: "GET",
url: this.url,
data: dataToGet,
context: this,
success: this.onSuccess
});
};
UpdateWebsiteBasedOnDBData.prototype.onSuccess = function(data) {
website.set(data);
alert( website.get("websiteID") );
};
$(document).ready(function() {
var updateWebsiteBasedOnDBData = new UpdateWebsiteBasedOnDBData();
updateWebsiteBasedOnDBData.readData({"websiteID": 2});
});
script.php は適切な json を返します。
{"websiteID":"2","タイトル":"タイトル サイト 2"}
更新:
まだ確認する必要がありますが、json が実際には無効であると強く疑っています。根本的な原因は、php スクリプトの文字セット (まだ検証中) である可能性があります。