我使用ajax用于laravel当前项目,我尝试使用ajax传递textbox的值,但每次都传递R
,即使我使用ajax传递了错误的变量。我的代码如下
<div class="form-group">
<label for="">Total Amount</label>
<input type="text" class="form-control" id="total_amount" value="123" name="total">
</div>
javascript代码
$("#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方法
public function getTotal(Request $request)
{
$list = @$request['lists'];
$total = @request['total'];
return $total;
}
varibale list
工作正常但total
总是返回值R
,当它第一次打印log
时,它在控制台中打印正确的值,但第二次在{ {1}} ajax的功能始终打印success
。在哪里我弄错了?
答案 0 :(得分:0)
改变这个:
$total = @request['total'];
到此:
$total = @$request['total'];
^
答案 1 :(得分:0)
尝试如下:
$("#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);
}
});
});