Backbone Paginator XML

时间:2013-07-07 11:17:45

标签: jquery xml backbone.js

我正在尝试使用TVDB Api,但由于他们使用的是xml,我在使用Backbone和Paginator插件时遇到了这两个错误:

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);
});

有人知道任何解决方案吗?

1 个答案:

答案 0 :(得分: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,将数据设置为模型并在内部使用它们。

相关问题