2013-07-08 22 views
0

我试图将值传递给PHP服务器端。我的商店代码如下;将Store中的值传递给PHP

Ext.define('MyApp.store.MyArrayStore', { 
    extend: 'Ext.data.Store', 

    requires: [ 
     'MyApp.model.MyMOD' 
    ], 

    config: { 
     autoLoad: true, 
     model: 'MyApp.model.MyMOD', 
     storeId: 'MyArrayStore', 
     proxy: { 
      type: 'ajax', 
      actionMethods: 'POST', 
      url: 'http://localhost/mm/app/php/res.php', 
      reader: { 
       type: 'json' 
      } 
     }, 
     listeners: [ 
      { 
       fn: 'onArraystoreBeforeLoad', 
       event: 'beforeload' 
      } 
     ] 
    }, 

    onArraystoreBeforeLoad: function(store, operation, eOpts) { 
     this.proxy.extraParams.VALUES1 = "pass some name here"; 
    } 

}); 

PHP代码

<?php 
error_reporting(E_ERROR | E_PARSE); 

require_once 'conn.php'; // contains the connection 

$v = $_POST['VALUES1']; 
echo json_encode($v); 

?> 

获取返回什么是null,而不是说我从店里传递(这是pass some name here)的值。

我该如何纠正?

UPDATE

Request URL:http://localhost/test/app/php/res.php?_dc=1373343459447 
Request Method:POST 
Status Code:200 OK 
Request Headersview source 
Accept:*/* 
Accept-Encoding:gzip,deflate,sdch 
Accept-Language:en-US,en;q=0.8 
Connection:keep-alive 
Content-Length:23 
Content-Type:application/x-www-form-urlencoded; charset=UTF-8 
Host:localhost 
Origin:http://localhost 
Referer:http://localhost/test/app.html 
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 
X-Requested-With:XMLHttpRequest 
Query String Parametersview sourceview URL encoded 
_dc:1373343459447 
Form Dataview sourceview URL encoded 
page:1 
start:0 
limit:25 
Response Headersview source 
Connection:Keep-Alive 
Content-Length:24 
Content-Type:text/html 
Date:Tue, 09 Jul 2013 04:17:39 GMT 
Keep-Alive:timeout=5, max=96 
Server:Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 
X-Powered-By:PHP/5.3.1 
+0

你有没有检查控制台中是否有错误..因为我的事情应该有一个错误.. – Viswa

+0

是的。错误是'Uncaught TypeError:无法读取未定义的属性'extraParams' –

回答

1

而不是this.proxy尝试this.getProxy()

我发现控制台对这类事情非常有用。在我自己的应用程序运行Ext.getStore('MyStore').proxy;让我undefined而Ext.getStore('MyStore').getProxy()让我的代理。

使用控制台,对我来说它是接下来API最有价值的开发工具。

祝你好运,布拉德

+0

是的,我也试过你的方法,但我仍然收到错误:'MyJsonReader1无法读取数据。 在浏览器中打开:http:// localhost ......'。 我认为这是因为PHP返回null(当我回应它的响应返回null)。所以我想''VALUES1'的值在PHP端没有被选中。任何线索如何解决这个问题? –

+0

使用开发人员控制台中的网络选项卡查看实际正在传递的参数。 – bwags

+0

它似乎没有得到发布(通过)。 –

2

您需要更改设置extraParams的方式。在这种情况下,我会使用

store.getProxy().setExtraParam('VALUES1','pass some name here'); 

如果您需要发送一个以上的参数,然后使用setExtraParams

var param = { VALUES1: 'param1', VALUES2 : 'param2'}; 
    store.getProxy().setExtraParams(param); 

如此充满店内码

Ext.define('MyApp.store.MyArrayStore', { 
    extend: 'Ext.data.Store', 

    requires: [ 
     'MyApp.model.MyMOD' 
    ], 

    config: { 
     autoLoad: true, 
     model: 'MyApp.model.MyMOD', 
     storeId: 'MyArrayStore', 
     proxy: { 
      type: 'ajax', 
      actionMethods: 'POST', 
      url: 'http://localhost/mm/app/php/res.php', 
      reader: { 
       type: 'json' 
      } 
     }, 
     listeners: [ 
      { 
       fn: 'onArraystoreBeforeLoad', 
       event: 'beforeload' 
      } 
     ] 
    }, 

    onArraystoreBeforeLoad: function(store, operation, eOpts) { 
     store.getProxy().setExtraParam('VALUES1 ','pass some name here'); 
    } 

}); 
+0

我仍然收到一个错误:'MyJsonReader1无法读取数据。 在浏览器中打开:http:// localhost ......'。原因是PHP返回null。所以我猜在PHP结束时没有选择VALUES1的值。任何线索? –

+0

它应该是'actionMethods'还是'actionMethod'? –