1$(document).ready(function(){
2
3 $("#but_upload").click(function(){
4
5 var fd = new FormData();
6 var files = $('#file')[0].files[0];
7 fd.append('file',files);
8
9 $.ajax({
10 url: 'upload.php',
11 type: 'post',
12 data: fd,
13 contentType: false,
14 processData: false,
15 success: function(response){
16 if(response != 0){
17 $("#img").attr("src",response);
18 $(".preview img").show(); // Display image element
19 }else{
20 alert('file not uploaded');
21 }
22 },
23 });
24 });
25});
1 $(function() {
2 $("#imagepicker").change(function(e) {
3 e.preventDefault();
4 var file_data = $(this).prop('files')[0];
5 var form_data = new FormData();
6
7 form_data.append('file', file_data);
8 form_data.append('action', 'ajax_image_upload');
9
10 $.ajax({
11 url: 'upload.php',
12 type: 'post',
13 contentType: false,
14 processData: false,
15 data: form_data,
16 success: function(response) {
17 console.log(response);
18
19 },
20 error: function(response) {
21 console.error(response.responseText);
22 }
23
24 });
25 });
26 });
1$(document).ready(function (e) {
2 $('#imageUploadForm').on('submit',(function(e) {
3 e.preventDefault();
4 var formData = new FormData(this);
5
6 $.ajax({
7 type:'POST',
8 url: $(this).attr('action'),
9 data:formData,
10 cache:false,
11 contentType: false,
12 processData: false,
13 success:function(data){
14 console.log("success");
15 console.log(data);
16 },
17 error: function(data){
18 console.log("error");
19 console.log(data);
20 }
21 });
22 }));
23
24 $("#ImageBrowse").on("change", function() {
25 $("#imageUploadForm").submit();
26 });
27});
28
1$("#changeProfilePicForm").submit(function (e) {
2 e.preventDefault();
3 var $form = $(this);
4 $.ajax({
5 url: $form.attr('action'),
6 type: "POST",
7 data: new FormData($form[0]),
8 contentType: false,
9 cache: false,
10 processData: false,
11 success: function (data) {
12 console.log(data);
13 },
14 error: function(data){
15 console.log(data);
16 }
17 });
18}));
1var form = new FormData();
2form.append('varName','data');
3$.ajax({
4 type:'POST',
5 url: $(this).attr('action'),
6 data:formData,
7 cache:false,
8 contentType: false,
9 processData: false,
10 success:function(data){
11 //function here
12 },
13 error: function(data){
14 //function here
15 }
16});