Trying to pass variables from JS to PHP file [on hold]











up vote
1
down vote

favorite












I'm trying to pass these variables via AJAX POST method from my JS file to my PHP file, but nothing goes thru. The console log is clean, and the table in the php page loaded, but the fields are empty. The idea is to set the variables in JS & then pass them into the php file to be displayed in the table.



Here's a Screenshot of the Chrome Window



Here's the .JS part:



    $.ajax({
type: "POST",
url: "test-php.php",
dataType: "text",
data: {
min: "D201522170",
invoice: 60,
sum: 60, // Replace with dynamic radio button values
descr: "Food Regime",
exp_date: "31.12.2018"
},
success: function(data) {
console.log(data);
}
});


And here's the .PHP part:



<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$min = $_POST['min'];
$invoice = $_POST['invoice'];
$sum = $_POST['sum'];
$exp_date = $_POST['exp_date'];
$descr = $_POST['descr'];

$data = <<<DATA
MIN={$min}
INVOICE={$invoice}
AMOUNT={$sum}
EXP_TIME={$exp_date}
DESCR={$descr}
DATA;


These variables are displayed on the screen in a table:



      <table class="striped">
<tbody>
<tr>
<td>Merchant Id</td>
<td> {$min}</td>
</tr>
<tr>
<td>Invoice Number</td>
<td>{$invoice}</td>
</tr>
<tr>
<td>Product Description</td>
<td>{$descr}</td>
</tr>
<tr>
<td>Payment</td>
<td>{$sum}</td>
</tr>
<tr>
<td>Total Amount</td>
<td>{$sum}</td>
</tr>
<tr>
<td>
</tbody>
</table>
?>









share|improve this question















put on hold as off-topic by ADyson, Masivuye Cokile, Billal Begueradj, Philipp, Blackbam yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – ADyson, Masivuye Cokile, Billal Begueradj, Philipp, Blackbam

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 4




    in your .js part you try to call jquery ajax function inside php tags
    – Oleg Nurutdinov
    yesterday










  • "Here's the .JS part:"....and yet it's enclosed in <?php tags....where are your <script> tags?
    – ADyson
    yesterday






  • 1




    @Pok3rPrinc3 edit the question and post correct
    – Masivuye Cokile
    yesterday






  • 2




    Ok, so then..."nothing goes through" is not an error message or problem statement. Have you used your browser's Developer Tools to try and debug the AJAX call? Is it sent? Is the data in the body correct? What status is returned? Are there any console errors? What about in PHP - how you are verifying that the $_POST data is not what you expected? You haven't given us any clear detail. I note you appear to have included the "success" callback within the data object itself, which I guess is a mistake. It may or may not be the cause of your problem, but without more info it's hard to be certain.
    – ADyson
    yesterday








  • 1




    @MasivuyeCokile no, it isn't.. the only wrong thing is, that success is inside data
    – Philipp
    yesterday















up vote
1
down vote

favorite












I'm trying to pass these variables via AJAX POST method from my JS file to my PHP file, but nothing goes thru. The console log is clean, and the table in the php page loaded, but the fields are empty. The idea is to set the variables in JS & then pass them into the php file to be displayed in the table.



Here's a Screenshot of the Chrome Window



Here's the .JS part:



    $.ajax({
type: "POST",
url: "test-php.php",
dataType: "text",
data: {
min: "D201522170",
invoice: 60,
sum: 60, // Replace with dynamic radio button values
descr: "Food Regime",
exp_date: "31.12.2018"
},
success: function(data) {
console.log(data);
}
});


And here's the .PHP part:



<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$min = $_POST['min'];
$invoice = $_POST['invoice'];
$sum = $_POST['sum'];
$exp_date = $_POST['exp_date'];
$descr = $_POST['descr'];

$data = <<<DATA
MIN={$min}
INVOICE={$invoice}
AMOUNT={$sum}
EXP_TIME={$exp_date}
DESCR={$descr}
DATA;


These variables are displayed on the screen in a table:



      <table class="striped">
<tbody>
<tr>
<td>Merchant Id</td>
<td> {$min}</td>
</tr>
<tr>
<td>Invoice Number</td>
<td>{$invoice}</td>
</tr>
<tr>
<td>Product Description</td>
<td>{$descr}</td>
</tr>
<tr>
<td>Payment</td>
<td>{$sum}</td>
</tr>
<tr>
<td>Total Amount</td>
<td>{$sum}</td>
</tr>
<tr>
<td>
</tbody>
</table>
?>









share|improve this question















put on hold as off-topic by ADyson, Masivuye Cokile, Billal Begueradj, Philipp, Blackbam yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – ADyson, Masivuye Cokile, Billal Begueradj, Philipp, Blackbam

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 4




    in your .js part you try to call jquery ajax function inside php tags
    – Oleg Nurutdinov
    yesterday










  • "Here's the .JS part:"....and yet it's enclosed in <?php tags....where are your <script> tags?
    – ADyson
    yesterday






  • 1




    @Pok3rPrinc3 edit the question and post correct
    – Masivuye Cokile
    yesterday






  • 2




    Ok, so then..."nothing goes through" is not an error message or problem statement. Have you used your browser's Developer Tools to try and debug the AJAX call? Is it sent? Is the data in the body correct? What status is returned? Are there any console errors? What about in PHP - how you are verifying that the $_POST data is not what you expected? You haven't given us any clear detail. I note you appear to have included the "success" callback within the data object itself, which I guess is a mistake. It may or may not be the cause of your problem, but without more info it's hard to be certain.
    – ADyson
    yesterday








  • 1




    @MasivuyeCokile no, it isn't.. the only wrong thing is, that success is inside data
    – Philipp
    yesterday













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm trying to pass these variables via AJAX POST method from my JS file to my PHP file, but nothing goes thru. The console log is clean, and the table in the php page loaded, but the fields are empty. The idea is to set the variables in JS & then pass them into the php file to be displayed in the table.



Here's a Screenshot of the Chrome Window



Here's the .JS part:



    $.ajax({
type: "POST",
url: "test-php.php",
dataType: "text",
data: {
min: "D201522170",
invoice: 60,
sum: 60, // Replace with dynamic radio button values
descr: "Food Regime",
exp_date: "31.12.2018"
},
success: function(data) {
console.log(data);
}
});


And here's the .PHP part:



<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$min = $_POST['min'];
$invoice = $_POST['invoice'];
$sum = $_POST['sum'];
$exp_date = $_POST['exp_date'];
$descr = $_POST['descr'];

$data = <<<DATA
MIN={$min}
INVOICE={$invoice}
AMOUNT={$sum}
EXP_TIME={$exp_date}
DESCR={$descr}
DATA;


These variables are displayed on the screen in a table:



      <table class="striped">
<tbody>
<tr>
<td>Merchant Id</td>
<td> {$min}</td>
</tr>
<tr>
<td>Invoice Number</td>
<td>{$invoice}</td>
</tr>
<tr>
<td>Product Description</td>
<td>{$descr}</td>
</tr>
<tr>
<td>Payment</td>
<td>{$sum}</td>
</tr>
<tr>
<td>Total Amount</td>
<td>{$sum}</td>
</tr>
<tr>
<td>
</tbody>
</table>
?>









share|improve this question















I'm trying to pass these variables via AJAX POST method from my JS file to my PHP file, but nothing goes thru. The console log is clean, and the table in the php page loaded, but the fields are empty. The idea is to set the variables in JS & then pass them into the php file to be displayed in the table.



Here's a Screenshot of the Chrome Window



Here's the .JS part:



    $.ajax({
type: "POST",
url: "test-php.php",
dataType: "text",
data: {
min: "D201522170",
invoice: 60,
sum: 60, // Replace with dynamic radio button values
descr: "Food Regime",
exp_date: "31.12.2018"
},
success: function(data) {
console.log(data);
}
});


And here's the .PHP part:



<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$min = $_POST['min'];
$invoice = $_POST['invoice'];
$sum = $_POST['sum'];
$exp_date = $_POST['exp_date'];
$descr = $_POST['descr'];

$data = <<<DATA
MIN={$min}
INVOICE={$invoice}
AMOUNT={$sum}
EXP_TIME={$exp_date}
DESCR={$descr}
DATA;


These variables are displayed on the screen in a table:



      <table class="striped">
<tbody>
<tr>
<td>Merchant Id</td>
<td> {$min}</td>
</tr>
<tr>
<td>Invoice Number</td>
<td>{$invoice}</td>
</tr>
<tr>
<td>Product Description</td>
<td>{$descr}</td>
</tr>
<tr>
<td>Payment</td>
<td>{$sum}</td>
</tr>
<tr>
<td>Total Amount</td>
<td>{$sum}</td>
</tr>
<tr>
<td>
</tbody>
</table>
?>






javascript php jquery ajax






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday

























asked yesterday









Pok3r Princ3

63




63




put on hold as off-topic by ADyson, Masivuye Cokile, Billal Begueradj, Philipp, Blackbam yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – ADyson, Masivuye Cokile, Billal Begueradj, Philipp, Blackbam

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by ADyson, Masivuye Cokile, Billal Begueradj, Philipp, Blackbam yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – ADyson, Masivuye Cokile, Billal Begueradj, Philipp, Blackbam

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 4




    in your .js part you try to call jquery ajax function inside php tags
    – Oleg Nurutdinov
    yesterday










  • "Here's the .JS part:"....and yet it's enclosed in <?php tags....where are your <script> tags?
    – ADyson
    yesterday






  • 1




    @Pok3rPrinc3 edit the question and post correct
    – Masivuye Cokile
    yesterday






  • 2




    Ok, so then..."nothing goes through" is not an error message or problem statement. Have you used your browser's Developer Tools to try and debug the AJAX call? Is it sent? Is the data in the body correct? What status is returned? Are there any console errors? What about in PHP - how you are verifying that the $_POST data is not what you expected? You haven't given us any clear detail. I note you appear to have included the "success" callback within the data object itself, which I guess is a mistake. It may or may not be the cause of your problem, but without more info it's hard to be certain.
    – ADyson
    yesterday








  • 1




    @MasivuyeCokile no, it isn't.. the only wrong thing is, that success is inside data
    – Philipp
    yesterday














  • 4




    in your .js part you try to call jquery ajax function inside php tags
    – Oleg Nurutdinov
    yesterday










  • "Here's the .JS part:"....and yet it's enclosed in <?php tags....where are your <script> tags?
    – ADyson
    yesterday






  • 1




    @Pok3rPrinc3 edit the question and post correct
    – Masivuye Cokile
    yesterday






  • 2




    Ok, so then..."nothing goes through" is not an error message or problem statement. Have you used your browser's Developer Tools to try and debug the AJAX call? Is it sent? Is the data in the body correct? What status is returned? Are there any console errors? What about in PHP - how you are verifying that the $_POST data is not what you expected? You haven't given us any clear detail. I note you appear to have included the "success" callback within the data object itself, which I guess is a mistake. It may or may not be the cause of your problem, but without more info it's hard to be certain.
    – ADyson
    yesterday








  • 1




    @MasivuyeCokile no, it isn't.. the only wrong thing is, that success is inside data
    – Philipp
    yesterday








4




4




in your .js part you try to call jquery ajax function inside php tags
– Oleg Nurutdinov
yesterday




in your .js part you try to call jquery ajax function inside php tags
– Oleg Nurutdinov
yesterday












"Here's the .JS part:"....and yet it's enclosed in <?php tags....where are your <script> tags?
– ADyson
yesterday




"Here's the .JS part:"....and yet it's enclosed in <?php tags....where are your <script> tags?
– ADyson
yesterday




1




1




@Pok3rPrinc3 edit the question and post correct
– Masivuye Cokile
yesterday




@Pok3rPrinc3 edit the question and post correct
– Masivuye Cokile
yesterday




2




2




Ok, so then..."nothing goes through" is not an error message or problem statement. Have you used your browser's Developer Tools to try and debug the AJAX call? Is it sent? Is the data in the body correct? What status is returned? Are there any console errors? What about in PHP - how you are verifying that the $_POST data is not what you expected? You haven't given us any clear detail. I note you appear to have included the "success" callback within the data object itself, which I guess is a mistake. It may or may not be the cause of your problem, but without more info it's hard to be certain.
– ADyson
yesterday






Ok, so then..."nothing goes through" is not an error message or problem statement. Have you used your browser's Developer Tools to try and debug the AJAX call? Is it sent? Is the data in the body correct? What status is returned? Are there any console errors? What about in PHP - how you are verifying that the $_POST data is not what you expected? You haven't given us any clear detail. I note you appear to have included the "success" callback within the data object itself, which I guess is a mistake. It may or may not be the cause of your problem, but without more info it's hard to be certain.
– ADyson
yesterday






1




1




@MasivuyeCokile no, it isn't.. the only wrong thing is, that success is inside data
– Philipp
yesterday




@MasivuyeCokile no, it isn't.. the only wrong thing is, that success is inside data
– Philipp
yesterday












1 Answer
1






active

oldest

votes

















up vote
4
down vote













success function should be out side the data



$.ajax({
type: "POST",
url: "test-php.php",
dataType: "text",
data: {
min: "D201522170",
invoice: 60,
sum: 60, // Replace with dynamic radio button values
descr: "Food Regime",
exp_date: "31.12.2018"
},
success: function(data) {
console.log(data);
}
});





share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote













    success function should be out side the data



    $.ajax({
    type: "POST",
    url: "test-php.php",
    dataType: "text",
    data: {
    min: "D201522170",
    invoice: 60,
    sum: 60, // Replace with dynamic radio button values
    descr: "Food Regime",
    exp_date: "31.12.2018"
    },
    success: function(data) {
    console.log(data);
    }
    });





    share|improve this answer



























      up vote
      4
      down vote













      success function should be out side the data



      $.ajax({
      type: "POST",
      url: "test-php.php",
      dataType: "text",
      data: {
      min: "D201522170",
      invoice: 60,
      sum: 60, // Replace with dynamic radio button values
      descr: "Food Regime",
      exp_date: "31.12.2018"
      },
      success: function(data) {
      console.log(data);
      }
      });





      share|improve this answer

























        up vote
        4
        down vote










        up vote
        4
        down vote









        success function should be out side the data



        $.ajax({
        type: "POST",
        url: "test-php.php",
        dataType: "text",
        data: {
        min: "D201522170",
        invoice: 60,
        sum: 60, // Replace with dynamic radio button values
        descr: "Food Regime",
        exp_date: "31.12.2018"
        },
        success: function(data) {
        console.log(data);
        }
        });





        share|improve this answer














        success function should be out side the data



        $.ajax({
        type: "POST",
        url: "test-php.php",
        dataType: "text",
        data: {
        min: "D201522170",
        invoice: 60,
        sum: 60, // Replace with dynamic radio button values
        descr: "Food Regime",
        exp_date: "31.12.2018"
        },
        success: function(data) {
        console.log(data);
        }
        });






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited yesterday

























        answered yesterday









        Fathma siddique

        887




        887















            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules