- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Download file through an AJAX call in PHP
Using Ajax to download files is not considered to be a good idea. Instead, window.location = or document.location should be used.
The 'window.location' has the following characteristics −
- JavaScript enabling is required
- It doesn't need PHP.
- It helps show the content of the site, and redirects the user after a few seconds.
Redirect can be dependent on any conditions such as −
$success = 1 if ($success) { window.location.href = 'http://example.com'; }
A variable named ‘success’ is assigned with the value of 1. When this condition is satisfied, the window.location is used.
On running, the user is redirected to the website 'http://example.com'
Advertisements