1
Well, I have a button that when clicked should open another page, by clicking via Ajax the results of the bank. The problem is I have to pass an id through that button for the Ajax request. Making an analogy is like a button that would load a page with all the comments from an article. The id I should pass is the article id. In Ajax I take this article id and send it to my controller to do the query and return Json. Example of the button:
<div class="btn-group" role="group">
<a href="/projeto/fazer" data-id="{{$artigo->id}}" class="btn btn-default"><span class="glyphicon glyphicon-fire"></span> Fazer</a>
</div>
Example of how I am loading the result via ajax:
$(document).ready(function() {
var artigo_id = $(this).data('id'); //esse ID que quero receber do botão
$.ajax({
type: 'GET',
url: '/carrega/comentarios/artigo/' + artigo_id,
data: {
'_token': $('input[name=_token]').val(),
},
success: function (data) {
for (var i =0; i<data.length;i++){.........
Your question is very wide, try to put the snippet of code to which you had difficulty.
– Wictor Chaves
Place Techo’s HTML code and Javascript’s button and events
– Sveen
Good evening posted an example of the code.
– Roberto Gualberto
js is in a separate file.
– Roberto Gualberto