Kostar
Kostar

Reputation: 47

Using backbone and other apis

How would I use backbone to connect to third party apis?

Upvotes: 0

Views: 36

Answers (1)

Mike
Mike

Reputation: 1219

Well, you're running into the cross domain script error. So, one solution would be to change the data format into something that works cross domain, like JSONP. So your code becomes:

var TestModel = Backbone.Model.extend({
    urlRoot: "http://api.duckduckgo.com/?q=yellowstone+national+park&format=json&pretty=2"
});
var testModel = new TestModel({});
var test_data = testModel.fetch({
    dataType: 'jsonp',
    success : function (data) {
        console.log(data);
    }
});

Upvotes: 1

Related Questions