2013-07-07 57 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,将数据设置为模型并在里面使用它们。