我有以下内容:
DiaryEntries.Collection = Backbone.Collection.extend({
url: '/rest/diary/'
});
所以我发起了这样的集合:
var collection = new DiaryEntries.Collection()
然后collection.fetch()
返回:
Object {readyState: 1, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…}
abort: function ( statusText ) {
always: function () {
complete: function () {
done: function () {
error: function () {
fail: function () {
getAllResponseHeaders: function () {
getResponseHeader: function ( key ) {
overrideMimeType: function ( type ) {
pipe: function ( /* fnDone, fnFail, fnProgress */ ) {
progress: function () {
promise: function ( obj ) {
readyState: 4
responseJSON: Array[1]
responseText: "[{"DEID":"1","DEOwnerID":"1","DEClientID":null,"DEDateStart":"2013-06-28 00:00:00","DEDateEnd":"2013-06-29 00:00:00","DEEventLocationID":null,"DEJobID":null,"DEName":"Ricky's test event","DELocation":"Kettering","DEFurtherDetails":"None","DEVisibility":"0","DENotes":"None","DEType":"1"}]"
setRequestHeader: function ( name, value ) {
state: function () {
status: 200
statusCode: function ( map ) {
statusText: "OK"
success: function () {
then: function ( /* fnDone, fnFail, fnProgress */ ) {
__proto__: Object
为什么不只是得到答复?我的mime类型为application/json
答案 0 :(得分:2)
调用服务器是AJAX调用(异步)。 fetch
返回的是XHR对象,而不是响应(因为服务器还没有响应)。要在客户端收到数据后执行某些操作,请使用回调或侦听器(或类似的东西)。
例如,您可以声明parse
方法来查看响应(它不是方法的实际目标,但无论如何):
DiaryEntries.Collection = Backbone.Collection.extend({
url: '/rest/diary/',
parse: function(response) {console.log(response); return response;}
});