tags:

views:

45

answers:

1

I use json data with jquery... I have filepaths in json and i am iterating with jquery...

var divs='';
$.each(jsob.Table, function(i, user) {
                divs += '<a class="download" href=' + user.resume_path + '/>'
            });
            $("#ResultsDiv").append(divs);

It works but how to make my anchor open file/save dialog box where the admin can download that resume... Any suggestion...

+1  A: 

Whether or not a document triggers a file save dialog is dependent on how the browser handles that file type. If it's something the browser knows how to display, either natively or via a plugin of some sort, it will display in the browser. If not, then the user will be prompted to save the document.

Jimmy Cuadra
Not necessarily - sending the right "content-type" and "content-disposition" in the http headers can help with this. For example, I was sending back CSV which was always opening in the browser (embedded Excel), however changing content type to "application/octet-stream" and disposition to "attachment" ensures that in 99.9% of cases, an "open/save" dialog is presented
Graza
@Graza - That doesn't contradict what I said. The browser will open a save dialog based on whether or not it knows how to present the type of file it's receiving. Of course changing the type of file you're accessing with headers will change what the browser ultimately does with it, but you cannot simply trigger a save dialog from JavaScript in the way the OP is requesting.
Jimmy Cuadra
Agreed, you definitely cannot do it with javascript. From the server end you also cannot do it in a way that guarantees a prompt (so yes you are correct). You can however send headers that increase your chances of getting an open/save prompt. It still doesn't guarantee that IE won't for example just open the document in the browser window, but means that in "most cases" it will prompt
Graza