如果点击div(非提交按钮)而不刷新页面,如何发布和返回图像?
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<input multiple class="fileInput" type="file" id="files" name="files[]"/>
<br>
<div id="submit" > click me to pass the photo to upload.php</div>
<div name="photoreturn"></div>
</body>
</html>
<style>
#submit{
background-color: #ffcc99;
display:inline-block;
padding:5px;
border-radius: 3px;
cursor:pointer;
}
</style>
答案 0 :(得分:0)
使用AJAX。每个人都这样做。
$("body").on("click", "#submit", function(e) {
e.preventDefault();
post_image();
});
function post_image() {
var img = find("input#files").val();
$.ajax({
url: './your_dir_here/upload.php',
type: 'POST',
data: img,
dataType: 'json',
success: function(data) {
$("#photoreturn").fadeIn("fast");
alert("img uploaded");
},
}); // End of ajax call
}
类似的东西。
注意:我还没有尝试过运行代码,您可能会收到错误,但这就是想法。祝你好运!
答案 1 :(得分:0)
您可以通过在div上添加onclick事件来调用ajax函数
tableMainContent.removeAllViews();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//Add view for table layout here
}
}, 2000);
<div id="submit" onclick="uploadImage()" > click me to pass the photo to upload.php</div>
ajax function