How to Get Answer from a Route with JS

Asked

Viewed 267 times

0

The route is configured this way:

Route::get('database/getClubes', 'DataBase@getClubes');

The Controller is like this:

public function getClubes()
{
    return ClubesDB::getClubes();
}

The Model looks like this:

public static function getClubes(){
    return ClubesDB::all();
}

The JS to get the answer is like this:

this.list = jQuery.get('database/getClubes');

However it does not return anything, when I access database/getClubes directly appears on the page the result, however when using jQuery does not return anything.

  • What appears on the console ?

  • Nothing, and return comes an entire page, and not just the bank result.

  • In the network tab it usually shows the requests where yours might be

  • In the Network tab you have a request called getClubes exactly what I want.

  • So master the information is coming properly need to see where you’re treating her

  • I took advantage and put a solution to your problem

Show 1 more comment

1 answer

1


The way you are using to popular the variable is not correct, try this way:

jQuery.get('database/getClubes', function(data){
    this.list = data;
    console.log(this.list); // vai trazer no console o resultado esperado.
});
  • I’m using this way the Vuejs <tr v-for="(item, index) in list"><td>{{item.clube}}</td> and even with the list filled, the table continues to do, already when I put something inside the list, works perfectly, what can be ??

  • Got a little confused your comment

  • Remembering that the get needs to be executed before the go to when it gets there it is populated and remembering that this is a different question I think it would be more prudent to address in another question and mark this as solved right ?

  • Let’s say it is constantly updated, which command can I use from Vuejs to update this table ??

  • Strange, if I add a new element in list it updates, but when I set a new whole list as is the case it does not update.

  • And if you loop the return and add one to one in the list ?

  • Again I suggest you mark as solved as different problems and open a new post with the data of the subsequent problem

  • Okay, I asked another question https://goo.gl/3CZ4dx

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.