简体   繁体   中英

Best method to get constantly updated json data in laravel

I'm trying to implement the jquery component jquery.mentionsInput on my laravel app.

Essentially I'll be using this so my users can @ mention other users in comment sections of a thread.

However, I want the callback to only fetch users who have posted in that thread, not all users on my site.

This jquery component fetches users one of two ways, the first is an existing array in JS: https://podio.github.io/jquery-mentions-input/assets/examples.js

The second is to fetch users from a json file like so: https://podio.github.io/jquery-mentions-input/assets/example2.js

So I'm guessing my best solution is to perhaps create a route in laravel that fetches the json data of all users for a particular post ID?

But I feel like this is perhaps not the best approach for this.

Suggestions?

Yes! you must create a separate route for each ajax operation. and send csrf in the header.

$.ajaxSetup({
    headers: {           
        'X-CSRF-TOKEN': csrfToken
    }

1.You can use continuous ajax. But its cause extra bandwidth loss.

2.I suggest You to use Laravel-echo with pusher .

https://pusher-community.github.io/real-time-laravel/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM