![](/img/trans.png)
[英]in extjs4, how to add a record to database? How php can received the data from ajax data(json format) translated by post method?
[英]why I can't get JSON from server in ExtJs4?
我想从服务器获取JSON,这是django服务器视图函数:
def showChart(request):
data = [{"id":1, "name":"Tom", "email":"a@a.com"}, {"id":2, "name":"Bosh", "email":"c@c.com"}]
return HttpResponse(json.dumps(data), mimetype="application/json");
显然,showChart()将返回一个json。
我的前端extjs4代码:
Ext.onReady(function() {
Ext.define('ProductionInfo', {
extend: 'Ext.data.Model',
fields: ['email', 'id', 'name']
});
var store_new = Ext.create('Ext.data.Store', {
model: 'ProductionInfo',
proxy: {
type: 'ajax',
url : 'http://localhost:8000/production_data',
reader: {
type: 'json'
}
}
});
store_new.load();
alert(store_new.getCount());
});
但是警报对话框显示“ 0”,而正确的答案是“ 2”。 那么,为什么我不能从服务器获取JSON? (我可以在Chorme和Firefox中通过GET请求获得正确的JSON)
您可以检查我的示例: https : //github.com/lucassus/extjs4-account-manager这是Rails应用程序,但是json机制非常相似。
基本上,您必须使用有效的proxy
定义模型: https : //github.com/lucassus/extjs4-account-manager/blob/master/app/assets/javascripts/app/model/User.js
以及具有model
属性的商店: https : //github.com/lucassus/extjs4-account-manager/blob/master/app/assets/javascripts/app/store/Users.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.