如何像在php中一样在javascript中使用文件内容(url)?还有别的选择吗?

如何像在php中一样在javascript中使用文件内容(url)?还有别的选择吗?,javascript,php,html,Javascript,Php,Html,下面是我的第一个URL const video_api_url="https://vsrequest.video/request.php?key=<>?&secret_key=<>&tmdb=1&ip=<>&video_id=" const video\u api\u url=”https://vsrequest.video/request.php?key=?&secret_key=&tmdb=1&ip=&

下面是我的第一个URL

const video_api_url="https://vsrequest.video/request.php?key=<>?&secret_key=<>&tmdb=1&ip=<>&video_id="
const video\u api\u url=”https://vsrequest.video/request.php?key=?&secret_key=&tmdb=1&ip=&video_id="
因此,可以使用id找到视频
这就是为什么我写了一个函数

function getInfo_OfSearchMovie(searchedMovies){
    const SearchMovie = document.createElement('div')
    SearchMovie.setAttribute('class','des');
    Search_movie_Template = 
    searchedMovies.map((movie)=>{
       const newVideo= video_api_url + movie.id // I HAVE USED THE ABOVE video_api_url HERE 
       
            return `
            <a href="${newVideo}"></a> // and then I have used that URl here..
           <iframe src="${newVideo}"&e=1" width="600" height="400" 
           frameborder="0" allowfullscreen="true" scrolling="no"></iframe>
            </h2>
           `
        });  
    
}
SearchMovie(searchedMovies)的函数getInfo{ const SearchMovie=document.createElement('div') SearchMovie.setAttribute('class','des'); 搜索\电影\模板= searchedMovies.map((电影)=>{ const newVideo=video\u api\u url+movie.id//我在这里使用了上面的video\u api\u url 返回` //然后我在这里使用了这个URl。。
因此,
const video\u api\u url=”https://vsrequest.video/request.php?key=?&secret_key=&tmdb=1&ip=&video_id=“
包含第二个URL,该URL是我想在
iframe标记中显示的视频。


在PHP中,我们可以使用file_get_Content(url),Javascript中的file_get_Content(url)还有其他替代方法吗?

据我所知,您希望显示多个iFrame。来自
searchedMovies
的每个视频一个iFrame

我将
.map
替换为
.forEach
,并在forEach循环中移动了
SearchMovie
的创建,以便为每部电影创建一个新的div

const video\u api\u url=”https://vsrequest.video/request.php?key=?&secret_key=&tmdb=1&ip=&video_id=";
SearchMovie(searchedMovies)的函数getInfo_{
searchedMovies.forEach((电影)=>{
const SearchMovie=document.createElement('div');
SearchMovie.setAttribute('class','des');
const newVideo=video\u api\u url+movie.id;//我在这里使用了上面的video\u api\u url
const videoHTML=`

`; SearchMovie.innerHTML=视频HTML; document.getElementById('searchResults').appendChild(SearchMovie); }); } 搜索引擎信息库([ {id:100}, {id:200}, {id:300}, ]);

演示:

如您所说,是PHP中的
文件获取内容()的替代方法

您可以使用
获取API
发出HTTP请求

根据您的问题,我假设
VIDEO\u API\u URL
返回一个基于
movie.id
的视频URL

如果每个
movie.id
都需要一个HTTP请求来获取URL,您可以使用下面的方法异步处理它们

在PHP中,文件内容是同步的

const video\u api\u url=”https://vsrequest.video/request.php?key=?&secret_key=&tmdb=1&ip=&video_id=";
SearchMovie(searchedMovies)的函数getInfo_{
//存储fetch返回的所有承诺。
const promises=searchedMovies.map(异步(电影)=>{
试一试{
//向API发出get请求
返回等待获取(video\u api\u url+movie.id);
}捕获(e){
错误(`Exception:${e}`);
}
});
//解析所有承诺后,将数据作为数组返回。
返回承诺。全部(承诺)。然后((数据)=>数据);
}
让video_url=getInfo_of searchmovie();
//循环浏览URL并为每个URL插入iframe
视频url.forEach((url)=>{
yourselector.insertAdjacentHTML('beforeend','`');
});
     <a href="${newVideo}"></a>
const video_api_url = "https://vsrequest.video/request.php?key=<>?&secret_key=<>&tmdb=1&ip=<>&video_id=";


function getInfo_OfSearchMovie(searchedMovies){
    // store all the promises returned by fetch.
    const promises = searchedMovies.map( async (movie) => {
       try {
           // make a get request to your API
           return await fetch(video_api_url + movie.id);
        } catch (e) {
           console.error(`Exception: ${e}`);
        }
    });
    // return the data as array after all the promises are resolved.
    return Promise.all(promises).then((data) => data);
}

let video_urls = getInfo_OfSearchMovie(<your_searched_movies>);

// loop through your urls and insert iframe for each
video_urls.forEach((url) => { 
    yourselector.insertAdjacentHTML('beforeend', `<iframe src="${url}">`); 
});