2013-07-07 50 views
2

我試圖使用TVDB API,但是因爲它們是使用XML,當我使用骨幹與分頁程序插件我得到這兩個錯誤:骨幹分頁程序XML

Resource interpreted as Script but transferred with MIME type text/xml: "http://thetvdb.com/api/GetSeries.php?seriesname=dexter&callback=jQuery19104464824248570949_1373195205356&_=1373195205357". jquery.js:5 
Uncaught SyntaxError: Unexpected token < 

我的js文件看起來像這樣:

Tv.Collections.Shows = Backbone.Paginator.requestPager.extend({ 
    paginator_core: { 
     url: Attr.tv.url, 
     type: 'GET', 
     contentType: 'text/xml', 
    }, 
    paginator_ui: { currentPage: 0 }, 
    server_api: {}, 
    parse: function(resp) { 
     c(resp); 
    }, 
}); 

,我使用它是這樣的:

Tv.search = new Tv.Collections.Shows; 
Tv.search.paginator_core.url = Attr.tv.url + $(ev.target).find('select').val() + '?seriesname=' + $(ev.target).find('.search_input').val(); 
Tv.search.fetch(function() { 
     c(Tv.search); 
}); 

有人知道任何解決辦法嗎?

回答

2

你可以很容易地使用一些很棒的服務,如Yahoo Pipes。我爲the tv db製作了一個管道。你可以在這裏查看 - http://pipes.yahoo.com/pipes/pipe.run?_id=2e4b059de7a389a0f361ca89b5f9c461&_render=json&seriesname=dexter

它是做什麼 - 將XML轉換爲JSON

而且,您創建網址的方式不是Backbone的方式。不要依靠DOM來處理您的數據。不要直接使用jQuery來獲取它們。取而代之的是events,將數據設置爲模型並在裏面使用它們。