在此代码中,URL返回数据,使用Object.values()在数组中获取数据的值。该数组由视频链接列表组成。使用邮递员时,链接有效,因为它们是新批处理。当我使用此代码将链接提取到视频播放器时,它会生成过期的URL。我也使用了无缓存。
async function postData(url = '', data = {}) {
// Default options are marked with *
const response = await fetch(url, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *client
body: JSON.stringify(data) // body data type must match "Content-Type" header
});
return await response.json(); // parses JSON response into native JavaScript objects
}
postData('http://127.0.0.1:5000/video', {'email': '', 'password': '' })
.then((data) => {
var x = Object.values(data);
console.log(x); // JSON data parsed by `response.json()` call
var mylapse = document.getElementById('timelapse');
var thislapse = x;
var activeVideo = 0;
mylapse.addEventListener('ended', function(e) {
// update the new active video index
activeVideo = (++activeVideo) % thislapse.length;
// update the video source and play
mylapse.src = thislapse[activeVideo];
mylapse.play();
});
});