Javascript 使用JSONP跨域使用WCF存储在datagrid中并查看数据dojo?
我在任何地方都找不到这个,我也不知道为什么dojo不能解决跨域REST请求。无论如何,问题出在这里: 我正在实现dojo数据网格,我正在尝试从不在我的域中的WCF获取网格的数据,因此我提出了跨域问题,我正在尝试使用JSONP来解决这个问题 但我是dojo的新手,所以我可能做错了什么。这是我的密码:Javascript 使用JSONP跨域使用WCF存储在datagrid中并查看数据dojo?,javascript,wcf,datagrid,dojo,jsonp,Javascript,Wcf,Datagrid,Dojo,Jsonp,我在任何地方都找不到这个,我也不知道为什么dojo不能解决跨域REST请求。无论如何,问题出在这里: 我正在实现dojo数据网格,我正在尝试从不在我的域中的WCF获取网格的数据,因此我提出了跨域问题,我正在尝试使用JSONP来解决这个问题 但我是dojo的新手,所以我可能做错了什么。这是我的密码: require([ "dojo/store/JsonRest", "dojo/store/Memory", "dojo/store/Cache",
require([
"dojo/store/JsonRest",
"dojo/store/Memory",
"dojo/store/Cache",
"dojox/grid/DataGrid",
"dojo/data/ObjectStore",
"dojo/query",
"dijit/form/Button",
"dojo/domReady!",
"dojo/request/script","dojo/dom-construct"
],function(script, domConstruct){
//make the request just as before
script.get("http://localhost:8060/ListService.svc/LoadLists?uid=c4446476-15e6-e111-9ecb-b7c5971d170a", {
jsonp: "callback",
query: {q: "#dojo"}
}).then(function(data){
test = data;
}).then(function(){
console.log(results);
});
}, function (JsonRest, Memory, Cache, DataGrid, ObjectStore ,query) {
grid = new DataGrid({
store: dataStore = test,
structure: [
{ name: "Blog Id", field: "id", width: "50px", },
{ name: "Name", field: "listtype", width: "200px",classes:"Name" },
{ name: "Phone Number", field: "longlevel", width: "200px",classes:"test" }
]
}, "gridTest"); // make sure you have a target HTML element with this id
grid.startup();
dojo.query("body").addClass("claro");
grid.canSort = function () { return false; };
});
我得到的错误是查询不是函数。任何关于如何正确实现的想法。简单的错误只需将数据网格命令放在第一个命令中,然后返回数据即可
require([
"dojo/store/JsonRest",
"dojo/store/Memory",
"dojo/store/Cache",
"dojox/grid/DataGrid",
"dojo/data/ObjectStore",
"dojo/query",
"dijit/form/Button",
"dojo/domReady!",
"dojo/request/script","dojo/dom-construct"
],function(script, domConstruct){
//make the request just as before
script.get("http://localhost:8060/ListService.svc/LoadLists?uid=c4446476-15e6-e111-9ecb-b7c5971d170a", {
jsonp: "callback",
query: {q: "#dojo"}
}).then(function(data){
function (JsonRest, Memory, Cache, DataGrid, ObjectStore ,query) {
grid = new DataGrid({
store: dataStore = test,
structure: [
{ name: "Blog Id", field: "id", width: "50px", },
{ name: "Name", field: "listtype", width: "200px",classes:"Name" },
{ name: "Phone Number", field: "longlevel", width: "200px",classes:"test" }
]
}, "gridTest"); // make sure you have a target HTML element with this id
grid.startup();
dojo.query("body").addClass("claro");
grid.canSort = function () { return false; };
})
}).then(function(){
console.log(results);
});
};
如果您仍然发现问题,可能是因为网格是在请求从wcf返回之前创建的
如果发生了这种情况,请使用Dojo1.8中的Deferred命令,它使您能够控制您的进程序列
因此,您将能够调用请求并给它一些时间,然后将数据放入网格中以供查看