在jquery中调用PHP函数时出错

时间:2014-07-07 10:54:54

标签: 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 it in to my custom PHP function to show the amount with currency.  

但问题是函数display_money将变量值作为字符串(remaining_amount)并创建问题以产生所需的结果。有点像(120 $)。

更新 以下是显示我如何使用remaining_amount的完整代码,它正在根据所选值进行更改。

//show the remaining amount 
            $("#selected_amount").live("change", function(event){
                var total_amount=$('#ta').html();
                var selected_amount=$(this).val();
                if(selected_amount=="")
                {
                    $('.remaining_amount_row').hide();
                    $('.final_withdraw').hide();
                    return false;
                }
                else
                {
                var remaining_amount= parseFloat(total_amount) - parseFloat(selected_amount);
                $('.remaining_amount').html(remaining_amount);
                $('.remaining_amount_row').show();
                $('.final_withdraw').show();
                return false;
                }
            });

1 个答案:

答案 0 :(得分:2)

尝试使用 - load()

var remaining_amount= parseFloat(total_amount) - parseFloat(selected_amount);// returns something like 120 
$('.remaining_amount').load('/display_money.php?remaining_amount='+remaining_amount);

display_money.php

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