uhbc
3075
90
Laravel

Ajax Get Method

Posted 1 year ago by uhbc

Hi, i can send data to db with using ajax post for the chat but can't use the ajax get for showing off the data in the screen. Can anyone help me about that?

Here is my db:

CREATE TABLE `chat` (
  `id` int(11) NOT NULL,
  `chat` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  `username` text NOT NULL,
  `userid` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

What i am currently using for retrieving data:

<div id="chat">
<ul class="list-group">
                          @foreach (App\ChatModel::chat() as $chat)
                          <li class="list-group-item" style="word-wrap:break-word;"><b>{{$chat->username}}</b>: {{$chat->chat}} </li>
                          @endforeach
                          </ul>
</div>

ChatModel:

  public static function chat(){
        $results = \DB::select(
          'SELECT * FROM (SELECT * FROM chat ORDER BY id DESC LIMIT 10) y ORDER BY y.id');


        return $results;

    }

I have to f5 the page to see what has just typed in the chat. Some said, i have to use the GET Method but i have no idea how to use it.

I used the $('#chat).load(' #chat); but thats not really effective. I want to get the data in the chat menu when a one is added. With a little animation

Please sign in or create an account to participate in this conversation.