javascript - Axios get request - img src link response format - / are being converted to spaces
问题描述
I am trying to generate a dynamic link to a movie poster using an Axios call.
function getMovies(searchText){
axios.get('https://api.themoviedb.org/3/search/movie?api_key='+ API_KEY + "&language=en-US&query=" + searchText + "&page=1&include_adult=false")
.then((response) => {
let movies = response.data.results;
let output = '';
$.each(movies, (index, movie) => {
console.log("http://image.tmdb.org/t/p/w185/" + movie.poster_path);
let movieUrl = "http://image.tmdb.org/t/p/w185/" + movie.poster_path;
output += `
<div class="col-md-3">
<div class="well text-center>
<img src="${movieUrl}" >
<h5>${movie.title}</h5>
<a onclick="movieSelected('${movie.imdbID}') target="_blank" class="btn btn-primary" href="#">Movie Details</a>
</div>
</div>
`;
});
$('#movies').html(output);
})
.catch((err) => {
console.log(err);
});
};
The console.log outputs the correct link syntax, for example: http://image.tmdb.org/t/p/w185//8WmT9i9sili2uLNzGGm3nc7AUR3.jpg
but on the DOM the link is formatted with spaces instead of / for example:
<img src=" http:="" image.tmdb.org="" t="" p="" w185="" 8wmt9i9sili2ulnzggm3nc7aur3.jpg"="">
What is going on here? Do I need to use something like paramsSerializer or encodeURI or is it something else?
解决方案
下面的class
属性值div
没有用双引号括起来。
<div class="well text-center>
浏览器只能尝试理解它,并将直到下一个字符的每个字符"
都img src="
视为.class
div
然后, 的值movieUrl
也被视为属性值,而不是没有正确转义。
关闭缺少的引号 ( <div class="well text-center">
) 应该可以解决该问题。
推荐阅读
- jquery - HereMap:在位置上悬停时移动地图
- python - 如何从 lambda aws -python 传递电子邮件正文中的变量
- python - Git Bash 没有按 python 2.7.18 的顺序处理我的打印语句和 raw_inputs
- intellij-idea - “将控制台输出保存到日志文件”在 IDEA 中不起作用
- sql - 获取以下条目不是+1分钟的所有条目
- dataframe - pyspark 未缩放的值对于精确火花来说太大了
- c# - Webclient 在尝试连接它发布的同一服务器时返回 500 错误
- laravel - 如何在 laravel 范围内使用模型函数?
- angular6 - 当我尝试对角度应用程序执行单元测试时..但是在运行测试时我遇到了错误
- jquery - JQuery Accordion,当你折叠一个手风琴时,它们都会折叠。我希望它只会折叠目标手风琴