Reputation: 53
nothing complicated here. just posting the data using ajax and its not working..
var ttc=$("#lblTot").val();
var tva=$("#prixTva").val();
var net=$("#prixNet").val();
var taxes=[ttc,tva];
var build="testing1212";
$.ajax({
type:'POST',
url:'passerCommande.php',
data: {
prices : net,
taxes : taxes,
build : build,
},
});
and here is my php file
<?php
error_reporting(0);
$itemPrices=$_POST['prices'];
$taxes=$_POST['taxes'];
$build=$_POST["build"];
$date=date("Y-m-d h:i");
echo "build : ".$build;
?>
i tried to "echo" the build but its empty.
Upvotes: 0
Views: 50
Reputation: 46
Are you sure it's call after page loaded if yes please check console by inspect elements and check errors and send me or if you don't know please run
$(document).ready(function (){
// your code.....
});
Upvotes: 0
Reputation: 1168
You have 3 errors in your JS function :
- "type" instead of "method" (see http://api.jquery.com/jquery.ajax/)
- you have an extra comma after "build" in the data values
- you have an extra comma after the data values
JS is not as permissive as PHP
$.ajax({
method:'POST',
url:'passerCommande.php',
data: {
prices : net,
taxes : taxes,
build : build
}
});
And you should use var_dump() instead of echo function
Upvotes: 0
Reputation: 1
You need to stringify your output:
$json = json_encode($build);
echo $json;
Upvotes: -1