You are assigning id to fields in loop. For every item in the loop, same id will be assigned which is not ideal because there should be only one id per page.
I cannot give perfect syntax but I can give you an idea.
You can assign onclick function to the button in the loop like:
<button type="button" class="btn btn-primary"
onclick="AddOrderFunc(name, description,price)" value="add">Order</button>
//Add parameters in function which you want to send
And in Javascript you can add function like:
function AddOrderFunc(name, description,price){
jQuery.ajax({
url: "{{ url('#') }}",
method: 'post',
data: {
name:name,
description:description,
price:price
},
success: function(result){
//console.log(result);
//jQuery('.alert').show();
//jQuery('.alert').html(result.success);
window.alert(result.success);
}});
});
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…