terror2012's avatar

Jquery update Element

Hello. I have a question on ajax in laravel. Let's say I have a {{$test['data']}} and in my controller, the $test['data'] is set to a value from a database. How can I use ajax to update this ? I basically need to refresh this element (not the whole page) so only would get a new value from database. Is there any way to do it? The real problem is that I have a register form and when someone registers, using redis/socket.io, I'm sending a message to client that someone registered, so I basically need to change the value from that div with new data for the last client, which means I need to somehow refresh that div without refreshing the page (as if I would refresh it, all the text from the form he completed will be lost).

0 likes
2 replies
Yann2006's avatar

I'm not sure if I'm really getting what exactly you want to do, but you can easily update an existing element based on the data coming back from an ajax call with something like this:

<span id="refresh-el">{{$test['data']}}</span>

<script>
$.get('url/to/endpoint',function(data){
    $('#refresh-el').text = data;
});
</script>
hendranucleo's avatar

You can use redis & socket.io but can't updating simple element? c'mon man, million of google result if you search for ajax update element on success call.

Please or to participate in this conversation.