Answer the question
In order to leave comments, you need to log in
How can PHP code (function) be output to an HTML page and actually process it?
There is an HTML page, with input, select(option), input(submit), etc. tags. I want to make sure that the code that is written in PHP works correctly and allows the user to download data on the same page on which he is located.
PHP code:
if($_POST['clause'] == 'submits')
{
header('Content-Type: text/plain; charset=utf-8');
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename=SocialHelperParsing.txt');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: private');
echo parserVK(); // Функция, в которой есть данные, которые необходимо выдать пользователю для сохранения на устройство.
exit();
}
function something(){
var sort_res = $('select[name=\'sortResults\'] option:selected').val();
var clause = 'submits';
$.post(myapi.php', {'sort_res':sort_res, 'clause': clause}, function(response) {
$('#downloadArea').html(response); // #downloadArea - это пустой <div>
});
};
Answer the question
In order to leave comments, you need to log in
Don't do it via ajax, just build the link you want. For example:
<a href='/your/script.php?clause=submits' target='_blank'>Скачать</a>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question