-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.php
64 lines (51 loc) · 1.59 KB
/
form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html>
<head>
<title>Upload</title>
</head>
<body>
<div style='display:inline-block;margin-right:10px' align="center">
<form action="" method="POST" enctype="multipart/form-data">
Upload Image:
<input type="file" id="image" name="image" required="">
<button type="submit">Upload</button>
</form>
</div>
<div class="status" style='display:inline-block;margin-right:10px'></div>
<div class="img" style='display:inline-block'></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e){
$("form").on('submit',(function(e){
e.preventDefault();
//var image = $("#image").val();
//var form = $('form')[0];
//var formData = new FormData(form);
$.ajax({
url:"upload.php",
type:"POST",
data: new FormData(this),
//dataType: 'json',
contentType:false,
cache:false,
processData:false,
success:function(response){
var res = JSON.parse(response);
console.log(res);
if(res.status == 1){
$('form')[0].reset();
$('.status').html('<h2 style="color:green" align="center">'+res.message+'</h2>');
$('.img').html('<img src="'+res.image+'" width="200" height="110">');
$("#list").load("index.php #list");
$("#deleted").load("index.php #deleted");
}else{
$('.status').html('<h2 style="color:red" align="center">'+res.message+'</h2>');
}
}
})
event.preventDefault();
}));
});
</script>
</body>
</html>