There is a file ( url ) which dynamically updates the value of tokens with each update ( request ) and contains approximately the following inside:

[{ "_id": "someidlikewewsdw", "type": 1, "name": "Channelname1", "logo": "/static/logos/channellogo1.png", "thread": "https://somesite.com/Channelname1/video.m3u8?token=33121", "enabled": true }, { "_id": "someidlikewewesq", "type": 1, "name": "Channelname2", "logo": "/static/logos/channellogo2.png", "thread": "https://somesite.com/Channelname2/video.m3u8?token=13121", "enabled": true }, { "_id": "someidlikewewesd", "type": 1, "name": "Channelname3", "logo": "/static/logos/channellogo3.png", "thread": "https://somesite.com/Channelname3/video.m3u8?token=23121", "enabled": true }] 

I need to assign the value of "thread" to a variable. Let us create the variables Channel1token, Channel2token, Channel3token and assign them the values ​​from theard each separately.

var Channel1token = https://somesite.com/Channelname1/video.m3u8?token=33121 and so on.

All this is needed in js so that the requests go from the client, since each client is assigned a separate token.

  • AJAX? What have you tried? What did not work out? If I understand correctly, then you need to request your "fileURL" using AJAX and use the received response further. What is the problem then specifically? - XelaNimed

1 answer 1

If I understand correctly, then you need to tear out separate threads from JSON. The easiest way to put them in an array. In this case, for chrome / mozilla the code will look like this:

 var channelTokens = []; $.ajax({url: "feeds.json"}) .done(function( data ) { data.forEach(feed => { channelTokens.push(feed.thread) }); console.log("We have tokens", channelTokens) }); 

Instead of console.log, you can already process the result.