0

I'm learning how to use Ajax in Jquery and I have no idea how to display the content that I receive back from the PHP. In the php file I'm just doing some calculations and I'm echoing the result (should I return it instead?), but the code below doesn't return anything. Nothing happens the div stays empty. This is my php code:

$totaalPrice = $totaal;
$roundUp =  number_format($totaalPrice, 2, '.', '');
$replace = str_replace(".", ",", $roundUp);
echo "Uw rit kost: € " . $replace . " euro<br>";

This is how I built my Ajax:

$.ajax({
  type: "POST",
  url: "brain.php",
  data: {km:km, time:time, day:day},
  succes: function(price){
  $('#showPrice').html(price).show(price); //This where I'm trying to display the result.
  },
  error: function(){
   alert('something went wrong..');}
});
3
  • 2
    Typo: succes vs success Commented Apr 10, 2022 at 12:42
  • 1
    Other than that, use console.log(price)/your browsers DevConsole to see what you get from that request Commented Apr 10, 2022 at 12:47
  • @brombeer Ahh thank you for helping! I removed the typo and the code works completely fine. Commented Apr 10, 2022 at 12:53

1 Answer 1

1
    $.ajax({
      type: "POST",
      url: "brain.php",
      data: {km:km, time:time, day:day},
      success: function(price){
      $('#showPrice').html(price);
      },
      error: function(){
       alert('something went wrong..');}
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.