Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.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 2 在sencha touch2中显示php文件中的数据_Sencha Touch 2 - Fatal编程技术网

Sencha touch 2 在sencha touch2中显示php文件中的数据

Sencha touch 2 在sencha touch2中显示php文件中的数据,sencha-touch-2,Sencha Touch 2,如何使用sencha touch2显示php文件中的数据?创建JSON存储并将url设置为php文件。在php文件中,使用json_encode()回显响应 您有几种方法可以实现它,但对我来说,我将使用json和Ext.ajax.request 例如,我的example.php看起来很简单,如下所示: $array = array( "go" => true, "message" => "Thank you for your message", ); 正如我所说,我

如何使用sencha touch2显示php文件中的数据?

创建JSON存储并将url设置为php文件。在php文件中,使用json_encode()回显响应

您有几种方法可以实现它,但对我来说,我将使用json和
Ext.ajax.request

例如,我的
example.php
看起来很简单,如下所示:

$array = array(
    "go" => true,
    "message" => "Thank you for your message",
);
正如我所说,我使用的是json,因此我需要对
$array
进行编码,以便在以后的视图中检索它

echo json_encode($array);
然后在您的视图中,您可以使用
Ext.util.JSONP.request()
从php文件中获取数据,但这里我将通过
Ext.Ajax.request()
来处理它:

Ext.Ajax.request({
  values : paramValues // values that you want to pass to example.php
  url: 'example.php',

  success: function(response) {
      //Here you need to decode the json data
      var data    = Ext.decode(response.responseText)
          go      = data.go,
          message = data.message;
      console.log(message); //Thank you for your message
  }

  failure: function(response) {
      console.log(response.responseText);
  }
});

这可能不是最好的方法,也可能会有错误,但至少我希望它会有用:)

我尝试了你的代码,但我得到了一个错误-未捕获的TypeError:无法调用未定义NotesListContainer的方法'request'。上面的js:2(匿名函数)只是一个示例代码,对我来说很好。我不知道你目前的代码,所以也许你需要自己定制。我从