0
鄉親們!使用ember-data存儲從跨域ajax請求的遠程服務器獲取的數據的任何示例?現在我有這個,但是......Ember.js餘燼數據和跨域阿賈克斯請求
TravelClient.Tour = Ember.Object.extend({
});
TravelClient.Tour.reopenClass({
allTours: [],
find: function(){
$.ajax({
url: 'http://someIP:somePORT/tours.json',
dataType: 'jsonp',
context: this,
success: function(data){
data.forEach(function(tour){
this.allTours.addObject(TravelClient.Tour.create(tour))
}, this)
}
})
return this.allTours;
}
});
UPDATE: 現在,我做了這種方式:
TravelClient.Tour.reopenClass({
allTours: [],
find: function(){
$.ajax({
url: 'http://someIP:somePORT/tours.json',
dataType: 'jsonp',
context: this,
success: function(response){
response.data.forEach(function(tour){
this.allTours.addObject(TravelClient.Tour.create(tour))
}, this)
}
})
return this.allTours;
}
});
但得到這個錯誤:
Uncaught TypeError: Cannot call method 'forEach' of undefined
SNAPSHOT:
這個:
$.ajax({
dataType: 'jsonp',
url:"http://192.168.1.39:3000/tours.json",
success:function(response){
return response.data;
}
});
我得到這個:
Object
abort: function (e){var t=e||S;return r&&r.abort(t),N(0,t),this}
always: function(){return i.done(arguments).fail(arguments),this}
complete: function(){if(a){var t=a.length;(function r(t){y.each(t,function(t,n){var i=y.type(n);i==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this}
done: function(){if(a){var t=a.length;(function r(t){y.each(t,function(t,n){var i=y.type(n);i==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this}
error: function(){if(a){var t=a.length;(function r(t){y.each(t,function(t,n){var i=y.type(n);i==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this}
fail: function(){if(a){var t=a.length;(function r(t){y.each(t,function(t,n){var i=y.type(n);i==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this}
getAllResponseHeaders: function(){return E===2?s:null}
getResponseHeader: function (e){var t;if(E===2){if(!o){o={};while(t=wn.exec(s))o[t[1].toLowerCase()]=t[2]}t=o[e.toLowerCase()]}return t==null?null:t}
overrideMimeType: function (e){return E||(c.mimeType=e),this}
pipe: function(){var e=arguments;return y.Deferred(function(n){y.each(t,function(t,s){var o=s[0],u=y.isFunction(e[t])&&e[t];i[s[1]](function(){var e=u&&u.apply(this,arguments);e&&y.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[o+"With"](this===r?n.promise():this,u?[e]:arguments)})}),e=null}).promise()}
progress: function(){if(a){var t=a.length;(function r(t){y.each(t,function(t,n){var i=y.type(n);i==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this}
promise: function (e){return e!=null?y.extend(e,r):r}
readyState: 4
setRequestHeader: function (e,t){var n=e.toLowerCase();return E||(e=b[n]=b[n]||e,g[e]=t),this}
state: function(){return n}
status: 200
statusCode: function (e){var t;if(e)if(E<2)for(t in e)m[t]=[m[t],e[t]];else x.always(e[x.status]);return this}
statusText: "success"
success: function(){if(a){var t=a.length;(function r(t){y.each(t,function(t,n){var i=y.type(n);i==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this}
then: function(){var e=arguments;return y.Deferred(function(n){y.each(t,function(t,s){var o=s[0],u=y.isFunction(e[t])&&e[t];i[s[1]](function(){var e=u&&u.apply(this,arguments);e&&y.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[o+"With"](this===r?n.promise():this,u?[e]:arguments)})}),e=null}).promise()}
__proto__: Object
請查看我的更新。 – xamenrax
你能提供你的回覆的快照嗎? – ken
查看答案中的快照。 – xamenrax