views:

87

answers:

1

Hi All

There is this 3rd party webservice. One of the public webmethods available is a GetDocument() method. This method returns a Document object. The Document object has properties for File(byte[]), ContentType(string) ect.

My Question : Can I subscribe to this service using javascript(mootools) + ajax + JSON, return the document object, in this case an excel document, and force the file download?

A: 

It is true that typically you cannot initiate a download from JavaScript, but there is a flash component, Downloadify that does enable client side file generation.

So you can serve files for download from HTML/JavaScript.

With that problem solved, you still have the problem of how to get the data that you wish to serve from the source web service.

3rd party implies XSS (cross site scripting) which is a no-no using XmlHttpRequest (Ajax).

A possible solution to this problem could be to use a common hidden IFrame technique to get the data.

Simply have an appropriate (hidden?) form that correctly posts to the web service and point it's action to an hidden IFrame element upon which you are trapping the Load event and parse the data returned.

But current browsers have different levels of security measures that limit your ability to access IFrames with an external source so you are actually stuck here. Sorry to get your hopes up.

The only practical robust way to accomplish what you would like to do is to have a local server side script that can act as a proxy between your HTML/JavaScript and the external web service.

Using such a proxy, you can simply go back to using Ajax to get your data to serve up with Downloadify.

But then, since you are using a server script to get the data, why not just serve the data from the script for download?

These are just my observations on the problem domain you present.

Sky Sanders