uhbc

Experience

1,400

0 Best Reply Awards

  • Member Since 4 Months Ago
  • 1 Lesson Completed
  • 0 Favorites

6th July, 2018

uhbc left a reply on Set Variable For JSON. • 2 weeks ago

Worked, thank you.

uhbc left a reply on Set Variable For JSON. • 2 weeks ago

It's trying to look for a data called 'variable' from JSON.

i want something like;

var variable = 'a1';
console.log( e[0].variable  );

So, i wanna see;

"1"

uhbc left a reply on Set Variable For JSON. • 2 weeks ago

I think i accidentally used a wrong url, fixed it anyways. Here is how it looks like:

[
{
act: null,
id: "1",
a1: "1",
a2: "0",
a3: "0",
u1: "ax-1",
u2: "ax-2",
u3: "ax-3"
}
]

But still can't do what i wanna do

uhbc left a reply on Set Variable For JSON. • 2 weeks ago

I am pretty sure that data is not empty

uhbc started a new conversation Set Variable For JSON. • 2 weeks ago

var variable = 'somevalue';

$.get(url, function(e){
console.log( e[0].variable );
});

How can i do something like this, i've tried almost everything but couldn't make it work.

-- The reason i wanna do that is, in the json output there are values like; a1, a2, a3 and i wanna get a1 when its 10pm and get a2 when its 5am ect.

I get an error like : " Cannot read property 'variable' of undefined "

Thanks.

7th April, 2018

uhbc left a reply on Ajax Get Method • 3 months 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 • 3 months ago

shouldnt

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

do that?

uhbc left a reply on Ajax Get Method • 3 months 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 • 3 months 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 • 3 months ago

Still couldnt

6th April, 2018

uhbc left a reply on Ajax Get Method • 3 months 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 • 3 months 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 • 3 months 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 • 3 months ago

Sent the wrong one sorry, changed it.

uhbc left a reply on Ajax Get Method • 3 months 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 • 3 months 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 • 3 months 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 • 3 months 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 • 3 months ago

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

uhbc left a reply on Ajax Get Method • 3 months 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 • 3 months ago

{"html":""}

uhbc left a reply on Ajax Get Method • 3 months 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 • 3 months 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 • 3 months ago

{"html":""}

uhbc left a reply on Ajax Get Method • 3 months ago

response is {"test":"value"}

uhbc left a reply on Ajax Get Method • 3 months ago

error log isnt changed.

uhbc left a reply on Ajax Get Method • 3 months 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 • 3 months ago

Done but now i see a blank page.

uhbc left a reply on Ajax Get Method • 3 months 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 • 3 months 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 • 3 months 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 • 3 months 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 • 3 months 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 • 3 months 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 • 3 months 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 • 3 months 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 • 3 months 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 • 3 months 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 • 3 months 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 • 3 months 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 • 3 months 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 • 3 months ago

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

uhbc left a reply on Ajax Get Method • 3 months 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 • 3 months 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 • 3 months 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 • 3 months ago

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

uhbc left a reply on Ajax Get Method • 3 months ago

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

uhbc left a reply on Ajax Get Method • 3 months ago

i got this error :

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

uhbc left a reply on Ajax Get Method • 3 months ago

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

uhbc left a reply on Ajax Get Method • 3 months ago

uhm. yes..

Edit Your Profile
Update

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