我不确定为什么会不断出现以下错误。Uncaught ReferenceError: jsonFlickrApi is not defined
我试图将包含URL参数的对象传递给ajax调用。
这是一个小提琴:http://jsfiddle.net/3vRM3/
这是我的JavaScript:
var TheModel = Backbone.Model.extend({
default: {
photos: '',
stat: ''
}
});
var TheCollection = Backbone.Collection.extend({
model: TheModel,
url: 'http://api.flickr.com/services/rest/'
});
// The main view
var List = Backbone.View.extend({
el: '.js-container',
initialize: function () {
this.collection = new TheCollection();
return this;
},
render: function () {
var self = this;
var urlParameters = {
page : '1',
api_key: 'xxxxxxxxxxxxxxxxxxxxx',
tags: "candy",
method: 'flickr.photos.search',
per_page: '3',
format: 'json',
jsoncallback: '?'
};
this.collection.fetch({
dataType: 'jsonp',
data: urlParameters,
success: function (data) {
console.log('success');
console.log(self.collection);
}
});
return this;
}
});
var myList= new List();
myList.render();
这是我的HTML:
<script type="text/template" id="DropdownList">
<% console.log('this is the template') %>
<h3>Stat = <%- collection[0].stat %></h3>
</script>
<div class="js-container">
</div>
最佳答案
查看响应:
jsonFlickrApi({"photos":{"page":1,"pages":144580,"perpage":3,"total":"433738","photo":[{"id":"13721741393","owner":"31558746@N00","secret":"1965a3793c","server":"5117","farm":6,"title":"Candy corn","ispublic":1,"isfriend":0,"isfamily":0},{"id":"13721755993","owner":"31558746@N00","secret":"c4eb729500","server":"2938","farm":3,"title":"Candy corn","ispublic":1,"isfriend":0,"isfamily":0},{"id":"13722064924","owner":"31558746@N00","secret":"b8662de0bb","server":"3723","farm":4,"title":"7-Layer Candy Dip","ispublic":1,"isfriend":0,"isfamily":0}]},"stat":"ok"})
他们正在使用JSONP并将回调设置为
jsonFlickrApi
关于javascript - FlickrAPI的jsonp问题:未捕获的ReferenceError:jsonFlickrApi未定义,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22945503/