日期:2014-05-16  浏览次数:20390 次

Ext Store获取服务器的json数据时显示下载框
最近遇到个奇怪的问题,使用Ext 的Store获取服务器的json数据时,浏览器显示一个下载对话框,下载的文件里就是json数据,不知道问什么浏览器把json数据当做文件下载了而不是存在Store中。

我的代码如下:


@{
  Layout = null;
}
<!DOCTYPE html>
<html>
<head>
  <title>Basic Tree Demo</title>
  <link type="text/css" rel="Stylesheet" href="../../ext-4.0.2a/resources/css/ext-all.css" />
  <script type="text/javascript" src="../../ext-4.0.2a/ext-all-debug.js"></script>
  <script type="text/javascript" language="javascript">
  Ext.onReady(function () {
  Ext.define('City', {
  extend: 'Ext.data.Model',
  fields: [{
  name: 'id', type: 'int'
  }, {
  name: 'name', type: 'string'
  }, {
  name: 'p_id', type: 'int'
  }, {
  name: 'iscity', type: 'boolean'
  }]
  });
  var citystore = Ext.create('Ext.data.Store', {
  model: 'City',
  proxy: {
  type: 'ajax',
  url: '../../Controllers/TreeDemoController/TreeCities',
  reader: {
  type: 'json',
  model: 'City'
  }
  },
  autoLoad: true
  });
  Ext.create('Ext.grid.Panel', {
  title: '城市表',
  store: citystore,
  columns: [{
  header: 'City Id', dataIndex: 'id'
  }, {
  header: 'City Name', dataIndex: 'name'
  }, {
  header: 'Parent Id', dataIndex: 'p_id'
  }, {
  header: 'Is City', dataIndex: 'iscity'
  }],
  renderTo: Ext.getBody()
  });
  });
  </script>
</head>
<body>
  <div>
  </div>
</body>
</html>


下载的文件里的内容是这样的:

[{"id":1,"name":"中国","p_id":0,"iscity":false},{"id":2,"name":"安徽","p_id":1,"iscity":false},{"id":3,"name":"江苏","p_id":1,"iscity":false},{"id":4,"name":"浙江","p_id":1,"iscity":false},{"id":5,"name":"合肥","p_id":2,"iscity":true},{"id":6,"name":"安庆","p_id":2,"iscity":true},{"id":7,"name":"芜湖","p_id":2,"iscity":true},{"id":8,"name":"南京","p_id":3,"iscity":true},{"id":9,"name":"杭州","p_id":4,"iscity":true},{"id":10,"name":"无锡","p_id":3,"iscity":true},{"id":11,"name":"苏州","p_id":3,"iscity":true}]

不知道错在哪里,请高手们指点,谢谢!


------解决方案--------------------
后台逻辑你写成了下载了吧