Question

My data sends to the db without issue, but the "file" input posting my photo into my BLOB field in my db does not post. I receive an error.

My code looks like:

   $(function(){
   $('#Userform').submit(function(event){
     var fd = new FormData( $(this)[0] );
   $.ajax({
     type: 'POST',
     processData: false,
     contentType: false,
         async: false,
         cache: true,
     data: fd,
     dataType: "text",
     url: 'mydburl.php',
        success: function(data){
        alert( data );
        alert('User successfully added');
     },
     error: function(){
        alert('There was an error adding New User');
     }
     });
     return false;

How would I append my data to include my photo "file" input? Any ideas would help. the name of my input is simply "photo". Without AJAX it posts fine when just sending to the form but because I am developing for devices, i need ajax to handle my form data. Any ideas would be helpful.

Thanks!

Was it helpful?

Solution

My original answer was wrong. Editing now:

Try to remove the dataType: "text" line from your ajax request.

Source: https://developer.mozilla.org/en-US/docs/Web/Guide/Using_FormData_Objects

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top