Trying to pass variables from JS to PHP file [closed]
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
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.
|
show 7 more comments
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
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
|
show 7 more comments
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
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
javascript php jquery ajax
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
|
show 7 more comments
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
|
show 7 more comments
1 Answer
1
active
oldest
votes
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);
}
});
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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);
}
});
add a comment |
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);
}
});
add a comment |
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);
}
});
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);
}
});
edited Nov 19 '18 at 10:39
answered Nov 19 '18 at 10:34
Fathma siddiqueFathma siddique
887
887
add a comment |
add a comment |
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