M
M
Macraen992021-08-14 13:54:31
AJAX
Macraen99, 2021-08-14 13:54:31

How can I automatically update the data on the page without reloading?

I am making a website for myself with information on the cost of a particular cryptocurrency. And I faced the problem of how to update the price, for example, for bitcoin, without reloading the page, as on COINMARCETCAP . I find out the price through api Binance like this

class MainController extends Controller
{
    public function index(){
        $url = Http::get('https://api.binance.com/api/v3/ticker/price');
        $json = json_decode($url, true);
        $tikers = collect($json);
        $btc = $tikers->where('symbol','BTCUSDT')->pluck('price')->first();
        return view('welcome', [
            'btc' => round($btc,2),
        ]);
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cython, 2021-08-14
@cython

As I understand it, you need to do it in real time. 2 technologies are suitable for this:
1. Server Sent Events: implementation on the client , on the server
2. WebSockets: client , library for laravel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question