在jquery中调用PHP函数时出错

在jquery中调用PHP函数时出错,php,jquery,Php,Jquery,我陷入了在Jquery中调用php函数的部分代码中。这是我的密码: var remaining_amount= parseFloat(total_amount) - parseFloat(selected_amount);// returns something like 120 $('.remaining_amount').html('<?php echo display_money('remaining_amount')?>');// here I need to pass i

我陷入了在Jquery中调用php函数的部分代码中。这是我的密码:

var remaining_amount= parseFloat(total_amount) - parseFloat(selected_amount);// returns something like 120 
$('.remaining_amount').html('<?php echo display_money('remaining_amount')?>');// here I need to pass it in to my custom PHP function to show the amount with currency.  
尽量使用-

display_money.php

if($_GET['remaining_amount'])
{
 // do the required task
}

PHP是在javascript之前在服务器端处理的,因此PHP函数display\u money没有剩余金额的概念。您需要在javascript中重写display_money函数。您需要知道无法在javascript中执行PHP函数之间的区别。好的,看来我需要为我的任务找到另一种方法。感谢您的回答,但剩余金额的值是在运行时确定的,这意味着它基于选定的_金额下拉列表,并根据选定的值。另一件事是我的目标是使用.html将这个计算值固定到特定的位置。请参阅我更新的问题。好吧,那么为什么要在javascript中使用php?您还可以使用javascript计算剩余的金额。而且你应该把总金额保存在一个隐藏的字段里。是的,这可能是使用java脚本函数的另一种方式,但我认为使用PHP函数更好。那么你找到解决方案了吗?我想是的。是的,我将使用Java脚本方法实现与PHP函数相同的功能。
var remaining_amount= parseFloat(total_amount) - parseFloat(selected_amount);// returns something like 120 
$('.remaining_amount').load('/display_money.php?remaining_amount='+remaining_amount);
if($_GET['remaining_amount'])
{
 // do the required task
}