Recently, I encountered such a function when I was working on a website. In the page as shown in the figure, when users need to click the link, they can judge whether the corresponding excel file is stored in the server in an asynchronous ajax way. If not, they will be prompted that they have not found it, and if so, they will download it to the local user.
Of course, this is a very simple problem. Just write Ajax in a normal way. But when the server returns the file content to the browser in binary form, the browser’s Ajax throws an error. It’s about parseError, invalid XML, PK, etc.
How to solve this problem?use window.location =URL is OK. Some people will ask, such as the above figure, when you click the download link on a certain page, because it has changed window.location Is the current page about to jump?In fact, I use Chrome browser. When I click that link, the next file save dialog box will pop up directly, and the address bar of the page has no change. At this time, if you click save, the file will be kept. If you click cacel, the operation will be cancelled. During the process, the current page will be kept and will not jump to other pages.
From personal blog www.sunrobin.net
- Security error: error ᦇ 2148
- JS opens a new tab（ window.open Application)
- Abnormal display of page object moved to here
- [solution] Google Chrome browser hijacked by hao123 chrome://version Command line tampered
- Configuration of OpenGL development environment under Windows environment, win10 + vs2019 + glfw + glad
- How do I download or save a YouTube video to my computer？
- How to install IDM Extension in Chromium-based Microsoft Edge (Canary/Dev)
- NS_ERROR_DOM_BAD_URI: Access to restricted URI denied
- Click the button to use in the react project window.open Methods open a new page and click the data again
- window.open () several ways to open windows
- Solve cannot execute binary file: exec format error under Linux
- Solve the Google Chrome Failed to load resource: net::ERR_FAILED problem
- When MyEclipse starts tomcat, the console doesn’t jump out
- Get picture captcha with Python + Chrome
- Solving windows error: [error 87] classification: problem summary
- Chrome local file translation tool
- Error note 404 error
- Solution of visdom enabling problem