dtxw20878
2015-12-03 16:42
浏览 79
已采纳

ExtJS 4:将复杂数据发送到服务器并在新的浏览器窗口中打开结果

I want to generate an .xlsx file on the server (using PHP if it metters) and open result (actually 'Save As...' window) in a new browser window. To generate file on the server I have to pass complex data (file settings) like:

[
    {
        'value1': 1,
        'value2': 2,
        'value3': 3
    },
    {
        'value4': 4,
        'value5': 5,
        'value6': 6
    }    
 ]

For this I doing something like:

Ext.create(Ext.form.Panel).submit({
    clientValidation: false,
    method: 'POST',
    params: [
        {
            'value1': 1,
            'value2': 2,
            'value3': 3
        },
        {
            'value4': 4,
            'value5': 5,
            'value6': 6
        }    
    ],
    standardSubmit: true,
    target: '_blank',
    url: 'my/real/url'
});

But on my server I keep getting wrong data, like

Array (
    [0] => [object Object]
    [1] => [object Object]
)

in my $_POST (where [object Object] is actual string) or

0=%5Bobject+Object%5D&1=%5Bobject+Object%5D

in my $data (Im using Slim framework)

$app->post('my/real/url', function () use ($app) {
    $request = $app->request();
    $data = $request->getBody();
});

Actually I tried many workarounds but I never get required data on my server side. Maybe I using wrong approach or just do it wrong?

图片转代码服务由CSDN问答提供 功能建议

我想在服务器上生成.xlsx文件(如果是metters则使用PHP)并打开结果(实际上是' 另存为...'窗口)在新的浏览器窗口中。 要在服务器上生成文件,我必须传递复杂数据(文件设置),如:

  [
 {
'value1':1,
'value2':  2,
'value3':3 
},
 {
'value4':4,
'value5':5,
'value6':6 
} 
] 
   
 
 

为此我做了类似的事情:

  Ext.create(Ext.form.Panel).submit({
 clientValidation  :false,
方法:'POST',
 params:[
 {
'value1':1,
'value2':2,
'value3':3 
},
 {\  n'value4':4,
'value5':5,
'value6':6 
} 
 
],
 standardSubmit:true,
 target:'_ blank',
 url:'my /  real / url'
}); 
   
 
 

但是在我的服务器上我一直收到错误的数据,比如

 数组(
 [0] => [对象] 
 [1] => [对象对象] 
)
   
 
 

在我的< 代码> $ _ POST (其中[object Object]是实际字符串)或

  0 =%5Bobject + Object%5D&amp; 1 =%5Bobject + Object%5D 
   
 
 

在我的 $ data 中(我正在使用) 超薄框架)

  $ app-&gt; post('my / real / url',function()use($ app){
 $ request = $ app-&gt  ; request(); 
 $ data = $ request-&gt; getBody(); 
}); 
   
 
 

实际上我尝试了很多变通方法,但我从未得到过 我服务器端需要的数据。 也许我使用错误的方法或只是做错了?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanjing7651 2015-12-03 21:51
    已采纳

    The reason is standardSubmit config will cause Ext JS to create a <form> and add items to that form with the values of the form items and the params you pass in. A <form> item cannot contain complex values like arrays or objects.

    You can encode your data before it's sent and then on the server decode it:

    Ext.create(Ext.form.Panel).submit({
        clientValidation: false,
        method: 'POST',
        params: {
            data: Ext.encode([
                {
                    'value1': 1,
                    'value2': 2,
                    'value3': 3
                },
                {
                    'value4': 4,
                    'value5': 5,
                    'value6': 6
                }    
            ])
        },
        standardSubmit: true,
        target: '_blank',
        url: 'my/real/url'
    });
    

    Then on your server, not sure about Slim framework (never used it), but with PHP you can use json_decode:

    $data = json_decode($_POST['data']);
    
    点赞 打赏 评论

相关推荐 更多相似问题