I need to build javascript that triggers on a click to <a>
element and invokes a GET call to a web service (I am coding the service also).
The service should return a file and only if no error occurred offer it for user to download from browser, otherwise leave him on the page where some other component will render the error.
The way I know to do it is to set "href" attribute of the <a>
element to the URL of the service.
Due to the specifics of the app I am building this for, I am not returning an error but html with "errorOccurred" content (it might be file with the same content too).
So, my question is: how to start file download from a javascript method (I am using jQuery.ajax) I have attached to onclick attribute of <a>
element only if the retrieved file content is ok?