0

When I sent the variable data through ajax loading_add.php page an error is displayed:

Uncaught ReferenceError: profit is not defined.

What I tried so far is attached below.

var profit = (
  Number($("#pro_price").val() - retail_price)
);

$.ajax({
  type: "POST",
  url: '../php/product/loading_add.php',
  dataType: 'JSON',
  data: {
      profit: profit
  };
Programmer Hari
  • 181
  • 1
  • 11

2 Answers2

1

In you php page just define variable as:

@$_POST['profit'];

you will not get undefined error again, hope this trick will help you :)

Therichpost
  • 1,759
  • 2
  • 14
  • 19
0

Your question is not clear.

But I share the valid way to send data via AJAX and retrieve the data in PHP Server Side..

var profit = (
    Number($("#pro_price").val() - retail_price)
);

console.log(profit); // see in console log if `profit` is a valid variable or not
$.ajax({
    type: "POST",
    url: '../php/product/loading_add.php',
    dataType: 'JSON',
    data: {
        profit: profit
    }
}).done(function(result){
    //do something after done AJAX
});

In server side, you must call variable $_POST['profit'] to retrieve the profit value.

Syamsoul Azrien
  • 2,534
  • 4
  • 32
  • 55