使用jsonp的extjs,从远程URL访问数据 [英] extjs using jsonp,Accessing data from remote url
问题描述
使用extjs,从一个系统运行服务器,在另一个系统中提供url,并在extjs版本4.02中使用JSONP,当我检查响应时以json格式获取数据时,尝试在控制台中打印或商店即时通讯没有得到..这是我的extjs代码...
with extjs,i m runnig the server from one system,giving the url in another system and i m using JSONP in extjs ver:4.02,when i check in response i m getting data in json format,when i try to print in console or Store im not getting..here is my extjs code...
<script type="text/javascript">
Ext.Ajax.cors = true;
Ext.Ajax.useDefaultXhrHeader = false;
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['empid', 'name', 'email']
});
var myStore = Ext.create('Ext.data.Store', {
model: 'User',
autoLoad:true,
proxy: {
type: 'jsonp',
// url : 'data/tagfamily.json',
url:'http://192.168.7.70:8080/palamanagement/user/getAllRecords',
},
listeners:{
'load':function( store, records, successful, eOpts ){
alert(records);
console.log(records);
}
}
});
推荐答案
您实际上必须返回如下内容:
You literally have to return something like the following:
someCallback({
users: [
{
id: 1,
name: "Ed Spencer",
email: "ed@sencha.com"
}
]
});
因此,您已经按照需要的方式拥有了JSON;您只需要服务器响应即可将JSON包装在回调中,以便JSONP代理可以执行并向商店加载数据.
So you already have the JSON the way you need it; you just need your server response to wrap the JSON in the callback so that the JSONP proxy can execute and load your store with data.
因此,在处理JSONP请求时,服务器的脚本需要识别作为请求的一部分发送的回调"参数.然后,它需要使用此参数的值来包装JSON响应.
Therefore, when handling the JSONP request, your server's script needs to recognize the "callback" param that is sent as a part of the request. It then needs to use the value of this param to wrap your JSON response.
请务必阅读我本人和Oguz都发布的文档:他们很好地概述了需求.但是,如果不使用回调进行响应,那么您将永远无法获得标准的JSON响应来与JSONP代理一起使用.
Be sure to read the docs that both myself and Oguz have posted: they outline the requirement pretty well. But if you don't respond with a callback, you'll never get your standard JSON response to work with the JSONP proxy.
这篇关于使用jsonp的extjs,从远程URL访问数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!