I have problems obtaining the value of the session variable jquery
using ajax
, since when I print I only get [object Object],[object Object] , but I do not get any value. It should be noted that if I do it POST
through a form, the page is reloaded (which I don't want) and there it does return the values from the controller. the code is the following.
In my view I have the following:
<a class="btn btn-warning btn-reservarG1" onclick="roomadd1();">A</a>
In my route:
Route::get('getrooms', function()
{
return response(['Hab' => \Session::get('roomcart')]);
});
My ajax jquery code is as follows:
<script type="text/javascript">
var roomadd1 = function()
{
var route = "getrooms";
$.get(route, function(data){
console.log("Valores"+data.Hab);
$("#nombrespru").val(data.Hab);
});
}
</script>
Note: He jquery
is in the same view.
It seems very silly reason =) why it shows me Object, but I didn't know, until I did a couple of tests. If I put console.log("Values"+responseobjects['habi']); It shows me [object][object] but instead if I place it like this it shows me the values console.log(responseobjects['habi']);
I share the solution with you
change the query
$.get()
to$.ajax()
, it is possible that it will solve the error, it would look like this: