uhbc

Experience

1,260

0 Best Reply Awards

  • Member Since 1 Month Ago
  • 1 Lesson Completed
  • 0 Favorites

7th April, 2018

uhbc left a reply on Ajax Get Method • 2 weeks ago

Actually, the main purpose was about the 'Get Method', I have no idea how to use that.

uhbc left a reply on Ajax Get Method • 2 weeks ago

shouldnt

success: function (response) {
                $('#chat > .list-group').append(response);
            }

do that?

uhbc left a reply on Ajax Get Method • 2 weeks ago

@jlrdw done that but didn't work. In case, shouldn't it display the message for the other users, even it doesn't happen for me? But that's not displaying for other users too.

uhbc left a reply on Ajax Get Method • 2 weeks ago

After submitting getting this in Response:

{"chat":"test123321123321","userid":131,"username":"asdasd","updated_at":"2018-04-08 02:04:28","created_at":"2018-04-08 02:04:28","id":664}

but still can't display it on the chat page.

uhbc left a reply on Ajax Get Method • 2 weeks ago

Still couldnt

6th April, 2018

uhbc left a reply on Ajax Get Method • 2 weeks ago

@Cronix then i replied with: If i do this, the page will be reloaded and its not really cool for the chat. Also, it doesnt data to db.

and then you: I don't think you copied everything correctly. The form shouldn't submit except by ajax. the e.preventDefault() makes it not submit the real form. You also had numerous items with the ID of "chat". ID's need to be unique per page.

I thought we were going on the old one after you said it.

uhbc left a reply on Ajax Get Method • 2 weeks ago

@jlrdw ofc that one will work but, its a chat, like do you reload the page in facebook when you are speaking with your friend?

uhbc left a reply on Ajax Get Method • 2 weeks ago

Actually same as i sent yesterday, i told you that i changed 'chat' into 'cett' and added console.log(response); after you told me to.

uhbc left a reply on Ajax Get Method • 2 weeks ago

Sent the wrong one sorry, changed it.

uhbc left a reply on Ajax Get Method • 2 weeks ago

<script>
$(document).ready(function(){


$('#send').click(function () {

  var cett = $('#cett').val();
  var username = $('#username').val();
  var userid = $('#userid').val();
  var token = $("#token").attr('content');


$.ajax({
  type:"POST",
  url:"{{url('chat')}}",
  data:"cett=" + cett + "&_token" + token,
  beforeSend: function(xhr){xhr.setRequestHeader('X-CSRF-TOKEN', $("#token").attr('content'));},
  success: function (response) {
    console.log(response);
    $('#chat > .list-group').append(response);
}

});
});
});

</script>

uhbc left a reply on Ajax Get Method • 2 weeks ago

@tykus, the view is at where you just said. I wrote that code and got this:

{"notifyType":"consoleItemLog","message":{"message":"","styles":"","hasFormatString":true,"fileUrl":"http:/site.com/home","lineNumber":150,"columnNumber":5}}

uhbc left a reply on Ajax Get Method • 2 weeks ago

i got this:

{"notifyType":"consoleItemLog","message":{"message":"","styles":"","hasFormatString":true,"fileUrl":"http://35.196.31.255/home","lineNumber":151,"columnNumber":5}}

uhbc left a reply on Ajax Get Method • 2 weeks ago

@tykus i changed codes into this and typed something:

    public function chat(Request $request) {
        // validate will throw a ValidationException if it fails, so no checks required
        $this->validate($request, [
            'cett'=> 'required|max:120|min:6',
        ]);

        // Since you have an Eloquent model, I am using that rather than Query Builder
        $chat = ChatModel::create([
            'chat' => $request->cett,
            'userid' => \Auth::user()->id,
            'username' => \Auth::user()->name // do you really need to store the user's name as well as the ID?
        ]);

        return dd($chat);
    }

I saw this in the chat after i sent it.: http://prntscr.com/j1v7n9

and the chat.message :

<li class="list-group-item" style="word-wrap:break-word;">
    <b>{{$chat->username}}</b>: {{$chat->chat}} ---
</li>

uhbc left a reply on Ajax Get Method • 2 weeks ago

But still, i have to f5 to see what is written

uhbc left a reply on Ajax Get Method • 2 weeks ago

Sorry, i got this one:

{"chat":"asdfsadfsadf","userid":128,"username":"Admin","updated_at":"2018-04-06 04:20:57","created_at":"2018-04-06 04:20:57","id":537}

uhbc left a reply on Ajax Get Method • 2 weeks ago

{"html":""}

uhbc left a reply on Ajax Get Method • 2 weeks ago

No, i still get that. And yes, we are almost there lol, i need to eat something too, enjoy and thanks mate.

5th April, 2018

uhbc left a reply on Ajax Get Method • 2 weeks ago

chats.message :

<li class="list-group-item" style="word-wrap:break-word;">
    <b>{{$chat->username}}</b>: {{$chat->chat}}
</li>

uhbc left a reply on Ajax Get Method • 2 weeks ago

{"html":""}

uhbc left a reply on Ajax Get Method • 2 weeks ago

response is {"test":"value"}

uhbc left a reply on Ajax Get Method • 2 weeks ago

error log isnt changed.

uhbc left a reply on Ajax Get Method • 2 weeks ago

Literally, there is no page when I try to reach the home page. So I can't even see a chat tab.

uhbc left a reply on Ajax Get Method • 2 weeks ago

Done but now i see a blank page.

uhbc left a reply on Ajax Get Method • 2 weeks ago

In here: http://prntscr.com/j1jcwb

Headers:
General:
Request URL: http://35.196.31.255/chat
Request Method: POST
Status Code: 200 OK
Remote Address: 35.196.31.255:80
Referrer Policy: no-referrer-when-downgrade

Form Data:
cett: asdfasdfasdf
_tokenin5cIFkBOSF13SfVwqLiDH9PQnNHdzBr450Szols: 

Response:
This request has no response data available

Cookies:
http://prntscr.com/j1jdb7

uhbc left a reply on Ajax Get Method • 2 weeks ago

How can i do that? Changed ajax codes into:

$.ajax({
  type:"POST",
  url:"{{url('chat')}}",
  data:"cett=" + cett + "&_token" + token,
  beforeSend: function(xhr){xhr.setRequestHeader('X-CSRF-TOKEN', $("#token").attr('content'));},
  success: function (response) {
        $('#chat > .list-group').append(response); // response will be a HTML string
        console.log(response);
    }

});

And in console, there is nothing

uhbc left a reply on Ajax Get Method • 2 weeks ago

There is nothing in the Console/Chrome, and in the Network section:

General:
Request URL: http://35.196.31.255/chat
Request Method: POST
Status Code: 200 OK
Remote Address: 35.196.31.255:80
Referrer Policy: no-referrer-when-downgrade

Form Data:
cett: asdfasdfasdf
_tokenin5cIFkBOSF13SfVwqLiDH9PQnNHdzBr450Szols: 

uhbc left a reply on Ajax Get Method • 2 weeks ago

Like in every chat site, you don't have to refresh the page because the things you write are automatically loading in the page, you are not being had to f5, but in my case, I have to refresh the page to see what people have typed.

uhbc left a reply on Ajax Get Method • 2 weeks ago

@Cronix, the problem was in the ChatModel after changing the $fillable, its fixed but. Still doesnt show off the data automatically.

uhbc left a reply on Ajax Get Method • 2 weeks ago

\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#65 /var/www/0/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#66 /var/www/0/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#67 /var/www/0/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#68 /var/www/0/public_html/index.php(55): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#69 {main}
"} 

uhbc left a reply on Ajax Get Method • 2 weeks ago

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use App\Http\Controllers\Auth;
use App\ChatModel;

class ChatController extends Controller
{

Still 500 (Internal Server Error)

uhbc left a reply on Ajax Get Method • 2 weeks ago

  <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use App\Http\Controllers\Auth;
use App\ChatModel;

class ChatController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }


    public function chat(Request $request) {
        // validate will throw a ValidationException if it fails, so no checks required
        $this->validate($request, [
            'cett'=> 'required|max:120|min:6',
        ]);

        // Since you have an Eloquent model, I am using that rather than Query Builder
        $chat = ChatModel::create([
            'chat' => $request->cett,
            'userid' => \Auth::user()->id,
            'username' => \Auth::user()->name // do you really need to store the user's name as well as the ID?
        ]);

        $view = view()->make('chats.message', compact('chat'));
        return $view->render();
    }



}

uhbc left a reply on Ajax Get Method • 2 weeks ago

Logs:

[2018-04-06 01:30:30] local.ERROR: Namespace declaration statement has to be the very first statement or after any declare call in the script {"exception":"[object] (Symfony\Component\Debug\Exception\FatalErrorException(code: 64): Namespace declaration statement has to be the very first statement or after any declare call in the script at /var/www/0/public_html/app/Http/Controllers/ChatController.php:3)
[stacktrace]
#0 {main}
"} 


uhbc left a reply on Ajax Get Method • 2 weeks ago

In the codes Tykus sent has:

      $chat = ChatModel::create([
            'chat' => $request->cett,
            'userid' => \Auth::user()->id,
            'username' => \Auth::user()->name // do you really need to store the user's name as well as the ID?
        ]);

Dont i also have to send the user's name, to see who sent the messages and show it on the screen?

uhbc left a reply on Ajax Get Method • 2 weeks ago

I changed the input id 'chat' into 'cett' and in from chatcontroller as well. Here is the data: http://prntscr.com/j1infc

but i still get the error '500 Internal Server Error'.

uhbc left a reply on Ajax Get Method • 2 weeks ago

If i do this, the page will be reloaded and its not really cool for the chat. Also, it doesnt data to db.

uhbc left a reply on Ajax Get Method • 2 weeks ago

<input type="text" id="chat" value="" placeholder="Type your message here.." maxlength="120" class="form-control" autocomplete="off"><br />
                      <input type="hidden" id="userid"  value="{{Auth::user()->id}}">
                      <input type="hidden" id="username" value="{{Auth::user()->name}}">
                      <input type="hidden" id="token" value="{{ csrf_token() }}">
                      <input type="submit" class="btn-info btn-muted" value="Send!" id="send">

scripts:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<link rel="stylesheet" href="{{asset('css/anim.css')}}">



<script>
$(document).ready(function(){
$('#send').click(function () {

  var chat = $('#chat').val();
  var username = $('#username').val();
  var userid = $('#userid').val();
  var token = $('#token').val();


$.ajax({
  type:"POST",
  url:"{{url('chat')}}",
  data:"chat=" + chat + "&userid=" + userid + "&username=" + username + "&_token=" + token,
  beforeSend: function(xhr){xhr.setRequestHeader('X-CSRF-TOKEN', $("#token").attr('content'));},
  success: function (response) {
        $('#chat > .list-group').append(response); // response will be a HTML string
    }

});
});
});

</script>

uhbc left a reply on Ajax Get Method • 2 weeks ago

Dont know why but somehow, getting this error: http://prntscr.com/j1icjt

uhbc left a reply on Ajax Get Method • 2 weeks ago

@Cronix when i hit submit and check the db, the 'This is a new data' text is in it. And when i wanna see the message in this here: http://prntscr.com/j1hses, i have to reload the page.

uhbc left a reply on Ajax Get Method • 2 weeks ago

I was using the exact code he wrote up there. After it didn't work, went back to the old one.

uhbc left a reply on Ajax Get Method • 2 weeks ago

Yes, when i add a new message, i have to F5 the page to see it. Not automatically appearing.

uhbc left a reply on Ajax Get Method • 2 weeks ago

Isnt that possible to get data without refreshing page? automatically? with a little effect

uhbc left a reply on Ajax Get Method • 2 weeks ago

Thanks but, now i have to f5 the page again to see what is written.

uhbc left a reply on Ajax Get Method • 2 weeks ago

i got this error :

Non-static method App\ChatModel::recent() should not be called statically

uhbc left a reply on Ajax Get Method • 2 weeks ago

I dont really know what to do, haven't seen a get method example before..

uhbc left a reply on Ajax Get Method • 2 weeks ago

uhm. yes..

uhbc left a reply on Ajax Get Method • 2 weeks ago

[email protected]:

public function index(){
return view('home');
}

uhbc left a reply on Ajax Get Method • 2 weeks ago

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
Route::get('/chat', '[email protected]')->name('getchat');
Route::post('/chat', '[email protected]')->name('chat');
      public function chat(Request $request){
        $validate = $this->validate($request, [
          'chat'=> 'required|max:120|min:6',
        ]);
        if($validate){
          $info = ['chat'=>$request->chat,
                       'userid'=>\Auth::user()->id,
                       'created_at'=>now(),
                       'updated_at'=>now(),
                       'username'=>\Auth::user()->name
                     ];
        $uhbc = \DB::table('chat')->insert($info);
      }else{
        return ('dont.');
      }
      }

uhbc started a new conversation Ajax Get Method • 2 weeks ago

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>

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

3rd April, 2018

uhbc left a reply on Chat System • 3 weeks ago

@Cronix thank you

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.