4
I’m trying to send a JSON
of view
for a route, but I’m not getting it. Unfortunately I know little about JSON
, ajax
, GET
and POST
.
In the view, the json:
var json = {
"numeroMesa": numeroMesa,
"itens": itens
};
Remembering that the variable numeroMesa
is a global variable in javascript
and itens
is an array with some numbers.
Soon after, I have:
$.get('addPedido/' + json, function(data) {
alert(data);
});
And on the route, I have:
Route::get('/addPedido/{json}', function($json) {
$json = JSON_decode($json);
return $json;
});
When sending, Alert shows nothing. I’m using framework laravel
.
Corrected. Not necessary
{json}
in that approach.– Wallace Maxters
Thank you very much! Unfortunately when I make these changes you asked for, I have an internal error (500 Internal Server Error). And there are still some doubts, can you help me? 1) Since 'items' is an array, it can have multiple elements stored. Can I still run it through a regular get request? (so I was trying to use a json) 2) On the route, when I type var_dump, how do I see the result of this, since it is not being returned to the view through the 'Return'? Anyway, thank you so much for the reply.
– Gabriel Augusto
@Gabrielaugusto can yes. The
jQuery
converts automatically. Take a test (to make you feel safer). Do this and see what appears on the console:console.log($.param(json))
.– Wallace Maxters
I found my mistake here, buddy, I was still spending $json on the route function. Thanks so much for the quick and direct help!
– Gabriel Augusto
Just one more question: is there any way for me to verify what is this internal error that happens? For example, if I do something silly on the route, using PHP, and give an error, is it possible to see what this error is? thank you!
– Gabriel Augusto
Yes. Go on
config/app.php
and configure the line"debug" => true
.– Wallace Maxters
This question here at SOPT would be important.
– Wallace Maxters