Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sencha touch rest代理url_Rest_Extjs_Sencha Touch 2 - Fatal编程技术网

sencha touch rest代理url

sencha touch rest代理url,rest,extjs,sencha-touch-2,Rest,Extjs,Sencha Touch 2,为什么如果使用JSON文件foo.JSON,我的代码可以工作,但是如果我将URL更改为something.com/foo.JSON,它就不能工作 这在我的项目中起作用: var store = Ext.create('Ext.data.Store', { model: 'Client', autoLoad: true, autoSync: true, proxy: { type: 'rest',

为什么如果使用JSON文件foo.JSON,我的代码可以工作,但是如果我将URL更改为something.com/foo.JSON,它就不能工作

这在我的项目中起作用:

var store = Ext.create('Ext.data.Store', {
        model: 'Client',
        autoLoad: true,
        autoSync: true,
        proxy: {
            type: 'rest',
            url : 'clients.json',
            reader: {
                type: 'json'
            }
        }
    }); 
我想要的是替换URL的静态文件:

var store = Ext.create('Ext.data.Store', {
        model: 'Client',
        autoLoad: true,
        autoSync: true,
        proxy: {
            type: 'rest',
            url : 'http://rails-api.herokuapp.com/clients.json',
            reader: {
                type: 'json'
            }
        }
    }); 

clients.json文件是相同数据的复制/粘贴文件。

在哪里运行应用程序?您能够跟踪http请求吗?在javascript控制台上有输出吗

如果要我猜的话,我会说你的问题可能与CORS=>有关

编辑: 请注意,如果在两个不同的Web服务器上运行应用程序和“后端”/api,则只需查看CORS或使用jsonp

大多数人可能会

  • a) …在与后端相同的Web服务器上运行应用程序,或
  • b) …使用本机包装(cordova、phonegap或sencha cmd自己的包装)

在这两种情况下,您都可以简单地使用“普通”ajax或rest代理。

在服务器端,我必须添加回调,请看这个问题。我还必须将类型从rest更改为,并删除一些无用的代码,最后我的代码如下所示:

var store = Ext.create('Ext.data.Store', {
        model: 'Client',
        autoLoad: true,
        autoSync: true,
        proxy: {
            type: 'jsonp',
            url : 'http://rails-api.herokuapp.com/clients.json'
        }
    }); 
在服务器端:

def index
    @clients = Client.all
    respond_to do |format|
        format.html 
        format.json { render :json => @clients, :callback => params[:callback] }
      end
end

我是新来的森查。。。现在,我正在我的PC上安装的apache tomcat中运行代码。我会看看CORS,我会让你知道,感谢现在它可以工作了,告诉我CORS真的很有帮助@Adrian,但它仍然不能解决整个问题,除非我将类型改为jsonp而不是rest。你应该仔细阅读文档。发出请求的服务器应通过
jsonp
类型响应
回调
。如果您在域上请求的url不需要使用
jsonp
。是的,但是webservice是公开的,所以我需要添加回调:)谢谢