Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using AJAX to get binary docs, is it possible 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I think i'm floggin a dead horse here, but maybe you guys can enlighten me.

I want to use AJAX to get a binary doc such as Word or Excel and print back to the browser in the same way you would normally do via a url using
Code:
Content-Disposition: attachment;

is this possible, and if so how, I just get the square blocks appear in a floated div if I print the return from the call, now I know AJAX is meant to be text/XML that is returned, so I think i cannot do this, but would appreciate guidance if there is some clever trick you can do to make it work.

I don't want to have to issue a window.open command, but if needs be and it's the only way, so be it.

All input greatly appreciated.

1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
You can set the encoding and use responseText to get any info you want but what will you do afterwards with the received file?

Cheers,
Dian
 
Hi

Do you not want to process the requested data in your script ? Otherwise I see no reason to involve AJAX in this.

As far as I know, the closest to what you described would be this :
Code:
location[teal].[/teal]href[teal]=[/teal][green][i]'data:application/octet-stream,'[/i][/green][teal]+[/teal][COLOR=darkgoldenrod]escape[/color][teal]([/teal]ajax[teal].[/teal]responseText[teal])[/teal]
Of course, the [tt]data:[/tt] URI support in Explorer is limited.

Feherke.
 
feherke,

this sounds exactly what I want, only I can't get it to work :-(

I use responseText in my AJAX call, but using the href code you supplied , nothing happens?

why would this be? I'm using IE8 and the document I'm testing with is an MS Word Doc.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Otherwise I see no reason to involve AJAX in this.
then the only other option is to open a new window , which most popup blockers will block which just cause problems of their own.

What else can i do? It's an intergtrated members extranet application i'm rewriting using AJAX, I don't want to 'change the page' using anchors and as a lot of user info is in the JS , it's a pain to build the anchor query string with the required user details, document requested, document type etc..

perhaps i'm coming at it from the wrong angle, what would you do?



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
sod it I answered my own question, i'll use an anchor and be done with it, at least it works and beats popup blockers.

Sometimes you just try to be too clever... I must keep telling my self...

K.I.S.S. -> Keep It Simple Stupid!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Hi

Should be added earlier that I never used that trick for binary data. Beside that, URL encoding is not really suitable for binary data and googling for and using a JavaScript base64 encoder would be better.

Anyway, glad to hear that you are going on the easy way.

Feherke.
 
But the way the document will open will depend on the user browser's configuration, right?

Cheers,
Dian
 
But the way the document will open will depend on the user browser's configuration, right?

yes and no, you tell the browser what the content is and its disposition via the headers you use from the serverside code.

However, the user gets the choice to tell the browser to not ask whether you want to open or save via the dialog box option.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top