PDA

View Full Version : How to post via AJAX request, and open binary file?



dbassett74
5 Jul 2010, 8:12 PM
I'm trying to open a binary file from the server after the user double-clicks an item in a grid. I'm guessing that the AJAX Request is not the proper mechanism for doing this as it never opens the file download window in the browser.

This has to be a POST request to the server which passes some parameters, so I'm not sure how to do this otherwise, as I can't just simply navigate to a specific URL. It has to be a POST.

Any help would be appreciated.

wm003
5 Jul 2010, 8:47 PM
Use the parameter "standardSubmit:true" in your FormPanel Config.

From the API Docs:
standardSubmit : Boolean If set to true, standard HTML form submits are used instead of XHR (Ajax) style form submissions. (defaults to false)...
If set to true, standard HTML form submits are used instead of XHR (Ajax) style form submissions. (defaults to false)
Note: When using standardSubmit, any the options to submit (http://localhost/extjs/ext-2.3.0/docs/output/Ext.form.BasicForm.html#submit) are ignored because Ext's Ajax infrastracture is bypassed. To pass extra parameters, you will need to create hidden fields within the form.

dbassett74
6 Jul 2010, 7:13 AM
I'm not using a FormPanel in this case. I'm making a direct call based on the user clicking something in the application, which is ViewPort based. There is no FormPanel. So how I can still utilize this?

mschwartz
6 Jul 2010, 8:28 AM
on success of your ajax call, you can do:

top.location.href = 'url_to_binary';

dbassett74
6 Jul 2010, 8:39 AM
But there is no "real" URL to the binary. For example, I make a post to the server such as someurl.com/process.aspx/GetFile. This is a post, so there is some parameters past with this call. The server then outputs a particular file.

mschwartz
6 Jul 2010, 8:45 AM
But there is no "real" URL to the binary. For example, I make a post to the server such as someurl.com/process.aspx/GetFile. This is a post, so there is some parameters past with this call. The server then outputs a particular file.

on success:

window.location='someurl.com/process.aspx/GetFile';

dbassett74
6 Jul 2010, 8:49 AM
Ya but, window.location is a GET method, right? How can I make that a POST method and pass parameters?

mschwartz
6 Jul 2010, 9:15 AM
Ya but, window.location is a GET method, right? How can I make that a POST method and pass parameters?

You have to submit a form to post, and you can target that form to a hidden iframe.