1

I have a page called index.php where I have some forms where the user must input information.
On this page I have this JQuery functions.

 else if (result == 3)
 {

     jQuery.get('sample.txt', function(data) {
         alert(data);
     });

 }

where the file sample.text its shown on an alert.

But, I have a page called download.php. When the user click on "submit" at page "index.php" , its send to the page "download.php", the values sent using Ajax POST.

var formData = new FormData($('#form_principal')[0]);
     $("#loading").show();

    setTimeout(function() {
        $.ajax({url: "/tkclientespdo/etiquetaslog/000/0000/download.php",
                  type: "post",

                  data: formData,
                  cache: false,
                  async:true,
                  contentType: false,
                   processData: false,
                  success: function(result)

on page "download.php" i have this variable :

$horaenvio = date("dmYGis");

after this variable i have a code :

echo 3;

that return the function at index.php . but i wanna change 'sample.txt" for the variable "$horaenvio".

someone could help.

4
  • If all you seem to be doing with ajax and php is formatting a date, why not just do it in javascript? Commented Aug 4, 2017 at 14:37
  • file_put_contents('path/to/sample.txt', $horaenvio);? Commented Aug 4, 2017 at 14:38
  • You mean $.get('<?=$horaenvio ?>', function(data) { Commented Aug 4, 2017 at 14:38
  • You could return a json string. <?php header('content-type: application/json; charset=utf-8'); echo json_encode(3); Commented Aug 4, 2017 at 16:40

1 Answer 1

0

You can use localStorage and storage event or SharedWorker to store the value data at index.php, and get the value at download.php, then .append() data to the FormData object, then echo the proper POST value.

Sign up to request clarification or add additional context in comments.

3 Comments

could u made a example ?
@Kamikaz0r Is download.php expected to be visited after .index.php?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.