Submit an image by ajax
Submit an image by ajax
Another question for you ...
Here there is the code complete:
http://jsfiddle.net/LQN43/1/
I need to submit some data by ajax to a file php ... all so ok for the text bu not for the image ... i have this code
HTML
<label>Name:<label><input class="name" /><br>
<label>Surname:<label><input class="surname" /><br>
<input type="file" class="selectImage" id="selectedImageFile" /><br>
<div style="border:1px solid; width:100px; height:100px">
<img id="uploadPreview" style="width:100%"/>
</div>
JQUERY
$(document).on('change', '.selectImage', function(){
var oFile = document.getElementById('selectedImageFile').files[0];
var oImage = document.getElementById('uploadPreview');
var oReader = new FileReader();
oReader.onload = function(e){
oImage.src = e.target.result;
};
oReader.readAsDataURL(oFile);
});
$(document).on('click', '.save', function(){
var name=$('.name').val();
var surname=$('.surname').val();
var img=document.getElementById('selectedImageFile').files[0];
$.ajax({
url: 'php/reqest.php',
type: 'post',
data: {'name': name, 'surname': surname, 'img': img}
});
});
Error Console
Uncaught TypeError: Illegal invocation
jquery-1.9.1.js:7340
Thanks for the support
Topic Participants
cecco974
jay.blanchard