使用ajax或javascript将组合框的选定值作为参数传递给特定的php函数

使用ajax或javascript将组合框的选定值作为参数传递给特定的php函数,javascript,php,jquery,ajax,laravel-4,Javascript,Php,Jquery,Ajax,Laravel 4,嗨,首先我会解释我想做什么,这样每个人都会清楚地了解我想做什么 我正在使用laravel框架开发一个应用程序,其中有一个编辑页面和一个php页面,即edit.blade.php和calculation.php edit.blade.php <script type="text/javascript"> function CompanyDepreciationCalculation() { debugger; var endFinanci

嗨,首先我会解释我想做什么,这样每个人都会清楚地了解我想做什么

我正在使用laravel框架开发一个应用程序,其中有一个编辑页面和一个php页面,即edit.blade.php和calculation.php

edit.blade.php

<script type="text/javascript">
    function CompanyDepreciationCalculation()
    {
        debugger;
        var endFinancialYear = $('#years').val();
        $('.display-table').html("<?php DepreciationCalculation2014(endFinancialYear); ?>");
    }
</script>

<div class="page-header">
    <h3>@lang('general.calculate_2014')</h3>
    <div class="pull-right">

    </div>
</div>

<div class="row form-wrapper">
    <form class="form-horizontal" method="post" action="calculation.php" autocomplete="off">
        <div class="form-group {{ $errors->has('years') ? ' has-error' : '' }}">
            <label for="shift" class="col-md-3 control-label calculate-label">@lang('admin/records/form.Calculate_dep')</label>
            <div class="controls col-md-7">
                <select name="years" class="controls assettext select2" id="years"  >
                    <option value=""> -- Select Year -- </option>
                    <?php
                    for ($i = 2014; $i <= 2101; $i++) {
                        echo "<option value=" . $i . ">" . $i . "</option>";
                    }
                    ?> 
                </select>
                <!--<a  class="btn btn-flat gray pull-right generatebtn">Next</a>-->
                <button type="button" class="btn btn-flat gray pull-right generatebtn" id="next" value="next" onclick="CompanyDepreciationCalculation()"><i class="icon-download-alt"></i>Generate  Depreciation Report</button>
            </div>
            {{ $errors->first('shift', '<span class="alert-msg"><i class="icon-remove-sign"></i> :message</span>') }}
        </div>
        <div  class="display-table" style="margin:70px 0px 0px -14px;">
        </div>
    </form>
</div>
function DepreciationCalculation2014($endFinancialYear) 
{ 
    //calculation stuff goes here and i display the calculated values in a table
}
问题是我无法在这里获取变量,它会抛出以下错误

Use of undefined constant selectedYear - assumed 'selectedYear' (View: C:\xampp\htdocs\AMS\app\views\backend\calculate2014\index.blade.php)
我尝试使用ajax,但没有成功

$(document).ready(function() {   
    $('#years').change(function() {debugger;
        $.POST('depreciationcalculation.php', $(this).serialize(), function(data) {
            alert(data);
        });
    });
});
和在php页面中

function DepreciationCalculation2014($endFinancialYear = 2014) 
{ 
    $_POST['years']
}

请帮我解决这个问题,我知道我做错了一些事情,但不太清楚。

这部分肯定不好:

<script type="text/javascript">
function CompanyDepreciationCalculation() {   
    debugger;
    var endFinancialYear = $('#years').val();
    $('.display-table').html("<?php DepreciationCalculation2014(endFinancialYear); ?>");
  } 
</script>

函数companyDepressionCalculation(){
调试器;
var endFinancialYear=$(“#years”).val();
$('.display table').html(“”);
} 
不能将这样的javascript变量传递给php

$('.display-table').html("<?php DepreciationCalculation2014(endFinancialYear); ?>");
$('.display table').html(“”);

改用ajax。

你可以通过一个例子更清楚地了解如何通过ajax实现它,因为我不知道如何在ajax中提及函数名和传递参数。