2016-07-23 142 views
0
$("#slider-range-max-day-count").slider({ 
       range: "max", 
       min: 1, 
       max: 365, 
       value: 1, 
       animate: "fast", 
       slide: function (event, ui) { 
        $("#dayCount").text(ui.value); 
        var invPackageValue = $('#investmentPackage').text(); 
        var dayValue = ui.value; 
        <?php 
        $compoundInterest = $CI->compound_int($package, $day, $interest_rate->static_interest); 
        ?> 
        $("#sliderResult").text(<?php echo $compoundInterest;?>); 
       } 
      }); 

在功能$CI->compound_int($package, $day, $interest_rate->static_interest);如何传递invPackageValue和dayValue代替$package$day参数。传递jquery的变量PHP函数作为参数

+0

这是一个PHP文件? –

+0

是的,这是php文件 – Ashish

+0

您应该使用ajax将jquery vaiables传递给PHP,然后您可以将它作为参数传递 –

回答

1

你应该在ajax中调用javascript变量。在ajax调用的请求中传递javascript变量。然后我们可以得到这些变量的php文件中的值,并在php文件中执行函数并返回输出,并且在ajax成功函数中我们可以得到响应。

// Javascript + Jquery code。

<script type="text/javascript"> 
    $("#slider-range-max-day-count").slider({ 
     range: "max", 
     min: 1, 
     max: 365, 
     value: 1, 
     animate: "fast", 
     slide: function (event, ui) { 
      $("#dayCount").text(ui.value); 
      var invPackageValue = $('#investmentPackage').text(); 
      var dayValue = ui.value; 
      $.ajax({ 
       url : 'PATH OF SAME FILE', 
       data : 'package='+invPackageValue+'&day='+dayValue, 
       type : 'post', 
       dataType : 'json', 
       success : function(data){ 
        $("#sliderResult").text(data.compoundInterest); 
       } 
      });   
     } 
    }); 
</script> 

// PHP代码

<?php 
    if(isset($_POST['package'])){ 
     $compoundInterest = $CI->compound_int($package, $day, $interest_rate->static_interest); 
     echo json_encode(['compoundInterest'=>$compoundInterest]);exit; 
    } 
?> 
+0

Thank @ rahul-patel,它工作得很好。 – Ashish