Send variable from javascript to php and receive it back as a link for file download -
i need send variable javascript php file receive link file download.
variable send list.php:
<a href="javascript:filesave(<?php $val ?>);">pdf</a> <script language="javascript" type="text/javascript"> function filesave($fid) { $.post( "getfile.php", { id: $fid }) ... ... </script>
link recieved getfile.php:
<?php if (isset ($_post['id'])) { $link = "./pdfs/vers".$_post['id']; } ?>
i want without page reload or redirect. can i?
if list.php , getfile.php on same server, can use ajax.
in javascript
function filesave($fid) { $.ajax({ type: 'post', url: 'list.php', data: { 'id': $fid },success: function(data){ // process after received data getfile.php } });
in php
if (isset($_post['id'])) { header("content-type: text/plain; charset=utf-8"); $link = "./pdfs/vers".$_post['id']; echo $link; }
Comments
Post a Comment