Home  >  Article  >  Backend Development  >  Download file via AJAX call in PHP

Download file via AJAX call in PHP

王林
王林forward
2023-09-05 11:33:06632browse

Download file via AJAX call in PHP

Using Ajax to download files is not considered a good idea. Instead, use window.location = or document.location .

'window.location' Has the following characteristics -

  • Requires JavaScript to be enabled
  • No PHP required.
  • It helps to display content website and redirect users after few seconds.

Redirection can depend on any condition, for example -

$success = 1
if ($success) {
   window.location.href = 'http://example.com';
}

A variable named "success" is assigned a value of 1. When this condition is met, window.location will be used.

When run, the user will be redirected to the website "http:" //example.com'

The above is the detailed content of Download file via AJAX call in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete