1
Eae guys, all right?
I would really like your help because I’ve been stuck in this problem for a couple of days and I couldn’t figure it out on my own.
I have a multi-row table with a checkbox on each row and a button that, when clicked, takes all the lines that are selected, stores the ids of those lines in an array, transforms the array into a json and requests a route by passing this json, where it will be manipulated to go through all ids and make database changes.
Initially it worked smoothly, but for a while it stopped working, I don’t know why.
Javascript function (in the view):
function tornarPendente() {
var arrayIds = [];
//pega todos os checkbox que estão selecionados e para cada um pega o ID referente ao aluno
$.each($('.checkbox1').prop('checked', 'checked'), function() {
var id = ($(this).attr('id'));
arrayIds.push(id); //coloca no vetor de ids
});
//converte o array em um json para passar para a rota
var json = {
"ids": arrayIds
};
$.get('../controle/concluidas/tornarTodasPendentes', json, function(data) {
window.location.reload(true);
});
}
Route
Route::get('/controle/concluidas/tornarTodasPendentes/', function() {
$input = Input::only('ids'); //recebe um array de ids
$input = $input['ids'];
foreach($input as $id) {
$aluno = new App\Aluno();
$aluno = $aluno->where('id', '=', $id)->first();
$aluno->pendente = '1';
$aluno->save();
}
return Redirect::back();
});
NOTE: Strange is the fact that if I change the address of the route to a route that does not exist, javascript does not return any error (even if I remove the part of window.location.reaload(true) ).
OBS2: If I give an Alert(json['ids']) I can see the ids normally.
Is there any way I know if these ids have at least reached the route?
Any kind of help would be welcome.
Thank you very much!
Spoke, spoke, spoke but did not say which error returns.. rsrsr. Have you checked the obvious? For example, is the url correct in ajax? It is pointing the way in a relative way. It may be that it is pointing to a non-existent or wrong path.. Anyway.. To help debug use your browser’s "Developer tools" console. On Chrome,
Ctrl+Shift+I
– Daniel Omine
So, friend, as I said in Obs 1, javascript does not return any error (in the console of Developer tools), and even stranger is that it does not return me any error even when I change this url to a route that does not exist. That’s why I wanted to know if there’s any way I can verify if the data was actually passed to the route or not, through PHP. The routes are correct, including this function worked before any changes I made, but now they are no longer working... Anyway thanks for the help.
– Gabriel Augusto
Reverse the change you made to the point where it worked then analyze what the change might have caused.
– Daniel Omine
About not returning error, it was unclear what returns. That’s what I meant. If no error returns, what then? Blank page? A message? What is the http status? anyway.. hard to know without having the parameters..
– Daniel Omine
To see debugging in the browser console, PHP has nothing to do with it. Open the browser tools (FF, Chrome, IE) and analyze the headers something like this. It usually stays in "Network". In Chrome it’s "Network" -> "Doc". Then you click on the document you want to analyze and see the logs. A tip, instead of using
alert()
to debug, use theconsole.debug(json['ids'])
, for example. Not that this will solve anything, but it is a better way to debug.– Daniel Omine
Another very grotesque way to test, go to the index.php of the Laravel and put a
print_r($_GET); exit;
well at the beginning, just to test. If receive then is good. The problem should not be javascript code. Then you already skip a step and do not waste time on javascript. It must be something that moved in the codes in the language as you mentioned yourself.– Daniel Omine
I tried to reverse the change, using git checkout for the old commit from six days ago inclusive, but it didn’t change anything. About the error, the page becomes static if I remove the line 'window.location.Reload(true)', but in network appears a new line as if OK, passing the ids, all right. Inclusive with a Status Code: OK (green). In Query String Parameters you pass all parameters normally (all ids).
– Gabriel Augusto
Thanks for the tip to use the console.debug, I will do this in the future. About print_r($_GET); Exit; at the beginning of the index.php file, nothing changes when I click on the button that makes the GET request, the page looks static the way it was. This, of course, if I comment on these commands until I reach the desired page and uncomment only at the time of clicking the button, after selecting the rows of the table. Otherwise, if I leave the commands when I enter the page, I have only one blank page written Array(). Anyway, thank you!
– Gabriel Augusto
Appears only as
array()
? then wouldn’t be getting as POST instead of GET? tryprint_r($_REQUEST); exit;
. And instead of testing by ajax, play directly in the url bar of the browser. .enfim.. search where the problem is, get it? Sure, don’t forget to clean up the mess with theseprint_r
andexit
right..– Daniel Omine