cause
The return value type of Ajax is Json,text,html,xml type, or it can be said that Ajax receive type can only be string string, not stream type, so file download cannot be implemented. However, the contents of the file can still be obtained with Ajax, the file will be kept in memory and the file cannot be saved to disk. This is because JavaScript cannot interact with the disk, otherwise this is a serious security problem, JS cannot call the browser's download processing mechanism and program, will be blocked by the browser. To implement a method of downloading a hidden form, the window.open () or window.location.href () created in the form of a submission form iframe,iframe src can be a file address URL to download the file directly
Note To set contenttype,content-disposition when downloading
Response. SetHeader ("Content-disposition", "attachment; Filename=123.doc ");
Response.setcontenttype ("Application/msword");
1. The return value type using Ajax,ajax is json,text,html,xml type, or it can be said that Ajax send, accept can only be string string, cannot stream type, so can not implement file download, strong use will appear response conflict.
If you want to use Ajax, you can only return file-related URLs that are worth generating. The callback function is then created by creating an IFRAME and setting its SRC value to the file URL, or a processing URL to the file generation stream, so that the file download is done and the page is not refreshed.
2. Do not use Ajax, through the DOM dynamic operation or create iframe,form way to achieve, while downloading the file implementation of the page is not refreshed, where the SRC can be a file address URL to download files directly, can also be a stream processing URL through the response stream output download, form is the stream processing URL through the response stream output download, Dom dynamic operation when the file download, and the page does not refresh.
to implement a progress bar while downloading, you can create a timed task that sends a request to the background at regular intervals, through common objects, such as sessions, to get the processing progress of the file download.