采购编号显示默认值而不是动态值

时间:2017-05-11 05:29:31

标签: php jquery laravel eloquent

我有以下AJAX,

  select: function(event, ui) {
    $( function() {
        var aravaitaken_date = $('#aravaitaken_date').val();
        var purchase_number = $('#purchase_number').val();
        var request = $.ajax({
            url: "getAravaiTotalbyDate",
            type: "POST",
            data: { aravaitaken_date: aravaitaken_date, purchase_number: purchase_number },
            beforeSend: function(){
                $('.calculation').html("<div class='row'><div class='col-md-12 text-center'><br/><br/><br/><br/><img src='images/ajax-loader.gif'/></div></div>");
            },
            success: function(data){
                $('.calculation').html(data);
            }
        });
    });
  }

和我提供的输入表格是

<label for="autocompletion">Purchase: </label> <input id="autocompletion">

各自的功能是,

public function getAravaiTotalbyDate(Request $request){

        $input = $request->all();
        $aravaitaken_date = $input['aravaitaken_date'];
    $purchase_number = $input['purchase_number'];

        $aravaitaken_date = date("Y-m-d", strtotime($aravaitaken_date));


    $aravaitaken_total_moottai = DB::table('take_aravais')->where('sale_date', '=',$aravaitaken_date)->where('purchase_number', '=', $purchase_number)->sum("moottai");
    $aravaitaken_total_kuvintal = DB::table('take_aravais')->where('sale_date' , '=', $aravaitaken_date)->where('purchase_number', '=',$purchase_number)->sum("kuvintal");

        $id = Settings::all()->last()->id;
        $percentage = Settings::findOrFail($id);
        $percentage_rice = $percentage->rice_percentage;
        $percentage_kurunai = $percentage->kurunai_percentage;
        $percentage_thavudu = $percentage->thavudu_percentage;

        $aravu_seithathil_varavu_total_kuvintal = $percentage_rice * $aravaitaken_total_kuvintal / 100;
        $aravu_seithathil_varavu_total_kuvintal_kurunai = $percentage_kurunai * $aravaitaken_total_kuvintal / 100;
        $aravu_seithathil_varavu_total_kuvintal_thavudu = $percentage_thavudu * $aravaitaken_total_kuvintal / 100;

        return view('Purchase.calculation', compact('percentage', 'aravaitaken_total_moottai', 'aravaitaken_total_kuvintal', 'aravu_seithathil_varavu_total_kuvintal', 'aravu_seithathil_varavu_total_kuvintal_kurunai', 'aravu_seithathil_varavu_total_kuvintal_thavudu'));

    }

输出就像显示的图像一样,

enter image description here

在这里我选择一个购买号码21,但它显示一些默认值为5,但我没有设置购买号码的任何值。当我安装它时,日期是正确的方式,但购买号码来了&#34; 5&#34;无论我输入的购买号码是什么,它只显示5 ..任何解决我的问题的帮助都会很明显..

1 个答案:

答案 0 :(得分:1)

我在这里看不到你的HTML代码,所以先查看你发送给ajax的购买号码

select: function(event, ui) {
$( function() {
    var aravaitaken_date = $('#aravaitaken_date').val();
    var purchase_number = $('#purchase_number').val();

//alert  a purchase number to check the value
alert(purchase_number);



    var request = $.ajax({
        url: "getAravaiTotalbyDate",
        type: "POST",
        data: { aravaitaken_date: aravaitaken_date, purchase_number: purchase_number },
        beforeSend: function(){
            $('.calculation').html("<div class='row'><div class='col-md-12 text-center'><br/><br/><br/><br/><img src='images/ajax-loader.gif'/></div></div>");
        },
        success: function(data){
            $('.calculation').html(data);
        }
    });
 });
}

如果购买编号正确,只需更改您的ajax数据

data: { "aravaitaken_date": aravaitaken_date, "purchase_number": purchase_number },

如果ajax和javascript部分的所有内容都正确,请检查php端如

public function getAravaiTotalbyDate(Request $request){

    $input = $request->all();
    $aravaitaken_date = $input['aravaitaken_date'];
    $purchase_number = $input['purchase_number'];

    echo $purchase_number;

}

我希望你能理解......