0
我需要將AJAX變量傳遞到我的視圖中,以便form action
正確執行。使用Laravel 5.4。和我(略)觀點是這樣的:如何將JS變量應用於Laravel表單操作
<div id="product_form" class="form-horizontal">
{{ Form::open(['action' => '[email protected]_product', // PRODUCT_ID MUST GO HERE]) }}
<div class=" form-group">
<div class="col-sm-2 col-md-2">{{ Form::label('product_name', 'Product Name:') }}</div>
<div class="col-sm-4 col-md-4">{{ Form::text('product_name',null) }}</div>
<div class="col-sm-2 col-md-2">{{ Form::label('product_id', 'Product Code') }}</div>
<div class="col-sm-4 col-md-4">{{ Form::text('product_id', null) }}</div>
</div>
我的Ajax功能正確傳遞所有的值到表單字段,但是我很努力讓product_id
成在操作語句的正確位置。 Laravel期望看到一個變量。
Ajax代碼(略):
select: function(event, ui) {
var product_id = (ui.item.value);
$.ajax({
url: "product_fullsearch/"+product_id,
dataType: "json",
type:"GET",
success: function (data) {
$('#product_name').val(data[0].product_name);
$('#product_id').val(data[0].product_id);
$("#supplier_name").val(data[0].supplier_name);
$("#supplier_id").val(data[0].supplier_id);
}
});//END AJAX
}
我看到這個Pass JS variable to form action對SO,給它一去,但我不能讓它在Laravel方面的工作。
我什麼東錯了?非常感謝 !