Hi,
I've a requirement which needs file download to be called from AJAX. can we make a call from AJAX so that content gets downloaded and file dialog box gets opened. Please help me.
and to donwload the dynamic file contents
hi dear,
there is so simple way.
yes you can do this.
use an iframe with visibility:hidden,
then need to change the IFrame location to a downloadable file.
TESTED in IE,FF
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-
<title>Untitled Document</title>
-
<script language="javascript">
-
-
function tryToDownload(url)
-
{
-
-
oIFrm = document.getElementById('myIFrm');
-
oIFrm.src = url;
-
alert(url);
-
-
}
-
window.onload = setTimeout('tryToDownload("fileloader.php?fileName=test.rar")', 5*1000);
-
-
</script>
-
</head>
-
-
<body>
-
-
<h1>DontChange the Location</h1>
-
<iframe id="myIFrm" src="" style="visibility:hidden">
-
</iframe>
-
-
</body>
-
</html>
-
and inside your server side code (like my php)
filename : fileloader.php
-
<?php
-
-
// set the header values
-
header("Content-Type: application/force-download\n");
-
header("Content-Disposition: attachment; filename=".$_GET['fileName']);
-
-
//set the value of the fields in Opened dailog box
-
header('Content-Disposition: attachment; filename="'.$_GET['fileName'].'"');
-
-
// echo the content to the client browser
-
readfile($_GET['fileName']);
-
-
?>
-
-
NOTE :
this script is so simple to teach the way,and its OUT OF SECURITY now.
so easy ;)
best regards.
mh