weixin_33725270 2017-04-29 07:30 采纳率: 0%
浏览 25

阿贾克斯得到错误的价值

I used ajax for my current project with laravel and i try to pass value of textbox using ajax but it pass R every time, even if i pass the wrong variable with ajax. my code is as below

 <div class="form-group">
    <label for="">Total Amount</label>
    <input type="text" class="form-control" id="total_amount" value="123" name="total">
 </div>

javascript code

    $("#id_label_multiple").on('change', function () {
        var list = $("#id_label_multiple").val();
        var total = $("#total_amount").val();
        console.log()
        $.ajax({
            url: "{{ action('hkcontroller@getTotal') }}",
            data: {
                lists: list, total: total, "_token": "{{ csrf_token() }}"
            },
            type: "POST",
            success: function (data) {
                $('#msg').html('Received ' + data + ' stones form exporter successfully!')
                console.log(data);
            }
        });
    });

laravel method

public function getTotal(Request $request)
{
    $list = @$request['lists'];
    $total = @request['total'];
    return $total;
}

varibale list work fine but total always return value R, when it print first time log that time it print correct value in console, but second time in success function of ajax it print always R. where i made mistake??

  • 写回答

2条回答 默认 最新

  • weixin_33736048 2017-04-29 07:36
    关注

    Change this:

    $total = @request['total'];
    

    to this:

    $total = @$request['total'];
              ^
    
    评论

报告相同问题?