Trying to pass variables from JS to PHP file [closed]












1















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















closed as off-topic by ADyson, Masivuye Cokile, Billal Begueradj, Philipp, Blackbam Nov 19 '18 at 10:47


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
    Nov 19 '18 at 10:28











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

    – ADyson
    Nov 19 '18 at 10:30






  • 1





    @Pok3rPrinc3 edit the question and post correct

    – Masivuye Cokile
    Nov 19 '18 at 10:31






  • 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
    Nov 19 '18 at 10:32








  • 1





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

    – Philipp
    Nov 19 '18 at 10:36
















1















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















closed as off-topic by ADyson, Masivuye Cokile, Billal Begueradj, Philipp, Blackbam Nov 19 '18 at 10:47


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
    Nov 19 '18 at 10:28











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

    – ADyson
    Nov 19 '18 at 10:30






  • 1





    @Pok3rPrinc3 edit the question and post correct

    – Masivuye Cokile
    Nov 19 '18 at 10:31






  • 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
    Nov 19 '18 at 10:32








  • 1





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

    – Philipp
    Nov 19 '18 at 10:36














1












1








1


0






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 Nov 19 '18 at 11:41







Pok3r Princ3

















asked Nov 19 '18 at 10:26









Pok3r Princ3Pok3r Princ3

187




187




closed as off-topic by ADyson, Masivuye Cokile, Billal Begueradj, Philipp, Blackbam Nov 19 '18 at 10:47


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.







closed as off-topic by ADyson, Masivuye Cokile, Billal Begueradj, Philipp, Blackbam Nov 19 '18 at 10:47


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
    Nov 19 '18 at 10:28











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

    – ADyson
    Nov 19 '18 at 10:30






  • 1





    @Pok3rPrinc3 edit the question and post correct

    – Masivuye Cokile
    Nov 19 '18 at 10:31






  • 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
    Nov 19 '18 at 10:32








  • 1





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

    – Philipp
    Nov 19 '18 at 10:36














  • 4





    in your .js part you try to call jquery ajax function inside php tags

    – Oleg Nurutdinov
    Nov 19 '18 at 10:28











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

    – ADyson
    Nov 19 '18 at 10:30






  • 1





    @Pok3rPrinc3 edit the question and post correct

    – Masivuye Cokile
    Nov 19 '18 at 10:31






  • 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
    Nov 19 '18 at 10:32








  • 1





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

    – Philipp
    Nov 19 '18 at 10:36








4




4





in your .js part you try to call jquery ajax function inside php tags

– Oleg Nurutdinov
Nov 19 '18 at 10:28





in your .js part you try to call jquery ajax function inside php tags

– Oleg Nurutdinov
Nov 19 '18 at 10:28













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

– ADyson
Nov 19 '18 at 10:30





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

– ADyson
Nov 19 '18 at 10:30




1




1





@Pok3rPrinc3 edit the question and post correct

– Masivuye Cokile
Nov 19 '18 at 10:31





@Pok3rPrinc3 edit the question and post correct

– Masivuye Cokile
Nov 19 '18 at 10:31




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
Nov 19 '18 at 10:32







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
Nov 19 '18 at 10:32






1




1





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

– Philipp
Nov 19 '18 at 10:36





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

– Philipp
Nov 19 '18 at 10:36












1 Answer
1






active

oldest

votes


















4














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









    4














    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






























      4














      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




























        4












        4








        4







        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 Nov 19 '18 at 10:39

























        answered Nov 19 '18 at 10:34









        Fathma siddiqueFathma siddique

        887




        887















            Popular posts from this blog

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)