L
L
LaJokero2017-05-20 23:46:58
css
LaJokero, 2017-05-20 23:46:58

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();
  }


The submit input has an onclick="something()" handler.

JS script:
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>
              });
          };


The question is, what am I doing wrong? It just returns the result of echo, but there is no writing to the file and no way to download it. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
ShagaevD, 2018-08-11
@ShagaevD

effect name Smoke Transitions

G
Georgy Bondarenko, 2017-06-02
@LaJokero

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 question

Ask a Question

731 491 924 answers to any question