Last post Sep 08, 2019 06:03 PM by aminsoraya
Sep 04, 2019 06:29 AM|aminsoraya|LINK
in our scenario the action returned two type of response in some condition s one of them may be partial view and another one can be file .
how to handle boths using unobtrusive ajax (if file return to download then show partial view)
Sep 04, 2019 07:16 AM|PatriceSc|LINK
Using jQuery ? My first thought would be to check the response header:
https://stackoverflow.com/questions/1557602/jquery-and-ajax-response-header for the text/html content type to show or trigger the download dialog. This last point can be done from Ajax using a trick such as https://stackoverflow.com/questions/20830309/download-file-using-an-ajax-request
I would still double check if it brings a real benefit and would try to make sure a simpler design can't fit my need.
Edit: ah or you meant you want to show a message "after" the download. I'm not sure it's really easy. The common pattern is likely to show a message when the download is triggered else it would be rather #2 above and then you do whatever you want after that.
Note that it prevents moving away from the page while the browser handles the download...
Sep 04, 2019 02:12 PM|bruce (sqlwork.com)|LINK
unobtrusive ajax only supports html/text response. on sucessful response, it set an inner div to the response. if the response is a binary file, then it will display it as bad unicode data.
the samples in the links download the file twice. once in ajax, and then again with the browser (location = url).
while you can use ajax to fetch a file, you can only save it to local storage, or if image encoded as a data url, display it as an image or canvas. but you will need to write your own ajax, not use unobtrusive.
Sep 08, 2019 06:03 PM|aminsoraya|LINK
the best way is reponse a jsons data that is contains the response type and if response type is okay then link of file (image) to show on end client browser.