Search code examples
extjsmodx

Posting Data to another Page ExtJs


I'm trying to post an array using a POST request to a specific page, the target page generates a csv and send me back the stream, right now i'm doing using ExtJs Ajax class, but that won't work as i need to make a normal HTTP request not ajax, my current code is as follows:

Ext.extend(Players.panel.Home,MODx.Panel,{
    exportSubscribers: function(btn,e) {
            MODx.Ajax.request({
                url: Players.config.connectorUrl 
                ,params: {
                    action: 'mgr/player/getSubscribers'
                }

            });
        }
});

The exportSubscribers function is executed from a normal ExtJs button

{ xtype: 'button'
  ,text: 'Export Subscribers'
  ,preventRender: true
  ,handler: this.exportSubscribers
    }

What class should i use to turn this into a normal request?

Thanks.


Solution

  • There isn't a class to do a normal request. I known two ways to accomplish a file download:

    • Use a hidden form in the page, replace the field values and invoke the form's .sumbit method from ExtJS button handler to do the POST request you want.
    • Replace your button by an HTTP anchor if you can use a GET request to make the server return the file: <a href="url?params" title="Download CSV">Download CSV</a>'