[英]fetch() not calling its Success and Error callback functions (backbone.js)
[英]backbone - no return after calling fetch success callback
這里的骨干js新手。 想知道是否有人可以幫助我解決同樣的問題。 我嘗試了上面的解決方案,但仍然沒有運氣。 我有與此帖子Backbone.js相同的問題-從url獲取JSON 。
這是我的代碼
// Model for News Releases
var NewsItem = Backbone.Model.extend({
¦ defaults: {
¦ ¦ releaseID: 'no releaseID at the moment',
¦ ¦ date: 'no date at the moment',
¦ ¦ title: 'no title at the moment'
¦ }
});
// Collection for our Model
var NewsItems = Backbone.Collection.extend({
¦ model: NewsItem,
¦ url: url + "/thewheelsonthebus.php",
¦ parse: function(response) {
¦ ¦ console.log(response);
¦ ¦ return response;
¦ }
});
var e = new NewsItems();
e.fetch({
¦ success: function(collection, response) {
¦ ¦ console.log('this should return something on console' + response);
¦ }
});
感謝@Wracker,解決此問題的方法是我返回了XML數據,而ajax調用無法找出輸出格式。.對此的解決方法是
默認情況下,會自動檢測到fileType,但在這種情況下,可能無法找出正確的格式。 因此,我嘗試將fileType顯式定義為xml / xthml / script ...
this.fetch({
dataType: "xml",
async: true,
success: function(collection, xml) { .... }
});
但是也有一個問題,您必須解析才能輸出到典型的javascript對象。 (在這種情況下,jQuery.parseXML()可能會派上用場)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.