×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Using AJAX to get binary docs, is it possible

Using AJAX to get binary docs, is it possible

Using AJAX to get binary docs, is it possible

(OP)
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!"

RE: Using AJAX to get binary docs, is it possible

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

RE: Using AJAX to get binary docs, is it possible

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 --> JavaScript ( fragment )

location.href='data:application/octet-stream,'+escape(ajax.responseText)
Of course, the data: URI support in Explorer is limited.

Feherke.
http://rootshell.be/~feherke/

RE: Using AJAX to get binary docs, is it possible

(OP)
feherke,

this sounds exactly what I want, only I can't get it to work sad

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!"

RE: Using AJAX to get binary docs, is it possible

(OP)

Quote:

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!"

RE: Using AJAX to get binary docs, is it possible

(OP)
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!"

RE: Using AJAX to get binary docs, is it possible

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.
http://rootshell.be/~feherke/

RE: Using AJAX to get binary docs, is it possible

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

Cheers,
Dian

RE: Using AJAX to get binary docs, is it possible

(OP)

Quote:

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!"

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close