Returning view from laravel controller to ajax request and populating data to div element, but not working if I insert any other string like .html("+++++") or if I use .text() it works but .html("") and .html(data) not working. Type of success:function(data) is string also and that string data is html table with laravel default pagination.
Table Data Receiving from controller in ajax success callback
<table class="table table-striped">
<thead>
<tr>
<td>Stock Name</td>
<!-- <td colspan="2">Action</td> -->
</tr>
</thead>
<tbody>
<tr>
<td>book</td>
<td><a href="http://localhost:8000/shares/1/edit" class="btn btn-primary">Edit</a></td>
<td>
<form action="http://localhost:8000/shares/1" method="post">
<input type="hidden" name="_token" value="lYeyrbyZpnFLqICDXgpXuqXPVEHX61gjJsWNDIIg">
<input type="hidden" name="_method" value="DELETE">
<button class="btn btn-danger" type="submit">Delete</button>
</form>
</td>
</tr>
</tbody>
</table>
<ul class="pagination" role="navigation">
<li class="page-item disabled" aria-disabled="true" aria-label="« Previous">
<span class="page-link" aria-hidden="true">‹</span>
</li>
<li class="page-item active" aria-current="page"><span class="page-link">1</span></li>
<li class="page-item"><a class="page-link" href="http://localhost:8000/sharesShow?page=2">2</a></li>
<li class="page-item"><a class="page-link" href="http://localhost:8000/sharesShow?page=3">3</a></li>
<li class="page-item">
<a class="page-link" href="http://localhost:8000/sharesShow?page=2" rel="next" aria-label="Next »">›</a>
</li>
</ul>
Ajax Function
$(document).ready(function(){
$('#searchBtn').click(function(e){
e.preventDefault();
var url = $("#searchForm").attr('action');
var data = $("#searchForm").serialize();
$.ajax({
url: url,
method: 'get',
data: {
"data": data,
"_token": ""
},
dataType: "html",
success: function(result){
console.log(result);
$("#divElement").empty();
}
});
});
});
Controller returning statement
$data = Share::paginate(1);
return view('shares.showAjax')->with('data',$data);
Div Element
<div id="divElement">
</div>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire