无法访问Dojo JsonRest存储中的数据,目标是PHP

时间:2013-03-28 22:38:28

标签: php json dojo

我正在尝试复制dojo / Store / jsonRest(v1.8)from here的dojotoolkit.org参考指南中的results.total示例。

我的jsonRest商店目标是一个php页面as I learned about here,我添加了console.debug(data);,它在firebug中显示数据是以我认为应该是的方式从php返回的:(抱歉试图显示pic在这里,但我不能)

问题是我无法弄清楚如何访问数据? results.total.then没有返回任何内容,我认为该功能甚至无法运行。

我尝试了store.get,这给了我一个404错误的php网址。我尝试像这样转换商店:newStore = ObjectStore({objectStore: store});然后在newStore上运行查询,这没有错误但也没有结果。

如果我尝试使用“foo = bar”语法查询商店,我也会收到404错误,在我的情况下为store.query ("ADDNUM='200'"),但如果我使用store.query ({ADDNUM:"200"})语法则没有错误。< / p>

我的最终目标是让结果显示在dojo过滤选择中,但是现在我会满足于能够到达它们,甚至只是console.log(结果)。
非常感谢任何人都能给予的帮助!

require([
  "dojo/store/JsonRest", 
  "dojo/data/ObjectStore", 
  "dojo/store/Memory"
  ], function(JsonRest, Memory, ObjectStore){
    var store = new JsonRest({
    target: "scripts/AddressNumTest.php"
    });

var self = this;
var results = store.query({ADDNUM:"200"}).then(function(data){
  console.debug(data);  //results from this look okay to me
  results.total.then(function(total){
     console.log("Never gets here??");
     console.log("total results: ", total);
     console.log("go on and use data ", data, " with this ", self);
     });
  });

//store.query("ADDNUM='200'")  //this returns 404 error

//below gives 404 error           
//var results2 = store.get({ADDNUM:"200"}).then(function(newdata){
//console.log("from get: " + newdata);            
//});

});

Result when no Error but also no success in accessing data in store: GET ../scripts/AddressNumTest.php?ADDNUM=200 200 OK -- RESPONSE: {identifier: 'OBJECTID', label: 'ADDNUM', 'items':[{"ADDNUM":"136","OBJECTID":"307"},{"ADDNUM":"150","OBJECTID":"308"},{"ADDNUM":"200","OBJECTID":"8494"},{"ADDNUM":"210","OBJECTID":"8495"},{"ADDNUM":"220","OBJECTID":"2950"}]}

404 Error when using store.get: GET .../scripts/AddressNumTest.php%5Bobject%20Object%5D 404 Not Found RequestError: Unable to load scripts/AddressNumTest.php[object Object] status: 404

404 Error when I use "ADDNUM='200'" syntax: GET .../scripts/AddressNumTest.phpADDNUM=%27200%27 404 Not Found RequestError: Unable to load scripts/AddressNumTest.phpADDNUM='200' status: 404

1 个答案:

答案 0 :(得分:1)

我不知道结果是否可用,但我认为你不需要它。回调传入data,在console.debug(data)中看起来不对您,所以让我建议这段代码。

var results = store.query({ADDNUM:"200"}).then(function(data){
  console.debug(data);  //results from this look okay to me
  console.log("You will get here!  :)");
  // I do not know what data looks like so this may or may not work.
  console.log("total results: ", data.total);
  console.log("go on and use data ", data, " with this ", self);
});