I have small problem, I need to use button from controller to work for JavaScript in view. I pass the HTML from controller to view, but it seems like the view doesn't see the button which comes from controller. Edited: I can display the data from controller into view blade with no error, what I want to do is just to use the button of these data which passed to view in other jquery function here how I recive the data from controller in view blade using the jquery function which sent from it the url and the data
success: function (data) {
$('#cart_product').html(data);
}
controller
public function edit(Request $request,$id){
foreach($products as $Product){
echo '<input id="rowId" class="remove_this btn btn-sm btn-danger" type="submit" name="rowId">';
}
}
view blade
<script>
$(function(){
$('.remove_this').on("click", function () {
alert('test');
});
});
</script>
First you have to SEND the data from controller to view. To do this you can write something like this (I've added products from request to foreach loop):
public function edit(Request $request,$id){
$output = '';
foreach($request->products as $Product){
$output .= '<input id="rowId" class="remove_this btn btn-sm btn-danger" type="submit" name="rowId">';
}
return view('YOUR-VIEW-PATH', compact('output'));
}
In the above code you save the data in a variable named $output and then send it to the view.
in the view you can access it this way:
{!! $output !!}
If you want to use it in JavaScript, I think you know how to do it.
<script>
var inputs = "{!! $output !!}";
</script>
Ok my answer is just to use the function of this button inside the response ajax which display these data inside blade view
success: function (data)
{
$(function(){
$('.remove_this').on("click", function () {
alert('test');
});
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.