javascript - Uploading/viewing image in website not working
问题描述
I am creating a web page where a user can upload an image and show it in the image container immediately. When I am running the file offline that is in my own computer then it is running fine, but when I am uploading it to the server it is not running.
In this web page when a user clicks on the image can SELECT file dialogue box gets opened from which the user can select an image. After selecting the image the image will be shown in the Image container.
When I am doing this in my computer it is showing the dialogue box and when the image is selected it is also loading the image in the image container, but when I am using 000webhost server for running this web page it is not even showing the select file dialogue box.
Code:
$("#blah").click(function(e) {
$("#fileToUpload").click();
});
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#blah')
.attr('src', e.target.result)
.width(150)
.height(200);
};
reader.readAsDataURL(input.files[0]);
}
}
@import url('http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css');
#blah {
border-radius: 50%;
}
#fileToUpload {
background-color: cyan;
display: none;
}
.border {
margin: 10%;
border: 2px solid black;
text-align: center;
padding-top: 10px;
padding-bottom: 30px;
background: #eee;
border-radius: 10px;
}
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script>
<body bgcolor=white>
<div class="border">
<img id="blah" src="profile-img.png">
<input name="fileToUpload" id="fileToUpload" type="file" placeholder="Photo" onchange="readURL(this);" />
</div>
<script>
</script>
</body>
解决方案
在脚本加载中使用 https 协议,如下所示:https ://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
这应该可以解决问题。
推荐阅读
- android - 是否可以重新路由 FCM 的应用内消息弹出窗口?
- php - 如何使用 eloquent 从数据库中检索 created_at 数据
- php - PHP中某个字符后1个字符的最小值
- python - 从从 CSV 文件加载的列表中删除括号和单引号
- python-3.x - 如何在使用 openpyxl 打开 excel 时强制使用数字/浮点分隔符?
- node.js - TypeORM:从订阅者中排除种子
- kubernetes - Ansible - 如果值不存在,则迭代项目并执行任务
- elasticsearch - Amazon Neptune 全文搜索 - 指定字段
- asp.net-core - 使用 Entity Framework Core 的 Blazor 并发问题
- android - 无法启动活动 ComponentInfo {className} java.lang.IllegalStateException:未找到颜色!(Android JetPack 撰写)