upload image ajax demo
$('#upload').on('click', function() {
var file_data = $('#sortpicture').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
alert(form_data);
$.ajax({
url: 'upload.php', // point to server-side PHP script
dataType: 'text', // what to expect back from the PHP script, if anything
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function(php_script_response){
alert(php_script_response); // display response from the PHP script, if any
}
});
});$(document).ready(function(){
$("#but_upload").click(function(){
var fd = new FormData();
var files = $('#file')[0].files[0];
fd.append('file',files);
$.ajax({
url: 'upload.php',
type: 'post',
data: fd,
contentType: false,
processData: false,
success: function(response){
if(response != 0){
$("#img").attr("src",response);
$(".preview img").show(); // Display image element
}else{
alert('file not uploaded');
}
},
});
});
});
Also in JavaScript:
- js string explode
- how to get textedit on mac without download
- get all parent nodes of child in javascript array
- javascript getelementbyid
- express pourquoi mettre bodyparser avant router
- console.log ejs
- javascript dictionary
- react quick tutorial
- sorting array from highest to lowest javascript
- lifecycle methods react
- react dom
- open folder node js
- jquery for bootstrap 4
- filter array objects javascript
- make random letter capital in string javascript
- if string have any digits javascript
- js generate list of names with forloop
- firestore update map
- javascript iterate through a binary tree
- js convert obj to array
- react component example
- responsive grid system angular
- functional component react with state
- set value of input javascript