[英]How to display data from PHP using Jquery Ajax?
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.我正在学习如何在 Jquery 中使用 Ajax,我不知道如何显示我从 PHP 收到的内容。在 php 文件中,我只是在做一些计算,我正在回应结果(我应该返回它代替?),但下面的代码不返回任何东西。 Nothing happens the div stays empty.
没有任何反应 div 保持为空。 This is my php code:
这是我的 php 代码:
$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 的方式:
$.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..');}
});
$.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..');}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.