I'm trying to pass 5 strings and some uploaded images as FormData with AJAX to a php script, the same php-file as the one that executes the ajax code (isolated by if($mode="edit"){ ... });
php file containing all the code: ?page=shop&mode=edit
ajax code:
$.ajax({
url: "?page=shop&mode=edit",
type: "POST",
dataType: 'multipart/form-data',
data: formData,
contentType: false,
cache: false,
processData: false,
success: function(phpfeedback) { console.log('success: '+phpfeedback); },
error: function(phpfeedback) { console.log('error: '+phpfeedback); }
});
php code:
if($mode=='edit'){
//php code that logs all feedback into $ajax_feedback
//I skip the phpcode as it is very long but it should be correct
echo $ajax_feedback;
}
when I execute the ajax code I get: error: [object Object] in the console.
Why don't I see the $ajax_feedback string? Please ask me if you need any more information, I really searched for hours on this.
dataTypeis to specify the return format, not the format of data you are sending to the PHP code. You could set it to something like JSON, and json_encode your data before returning it, especially if you might return more than one value. Right now, Ajax is expecting the return to be in "multipart/form-data" format, which you can't echo. I'm not even sure it will support returned data in that format, so maybe it's just confused.console.log('error: ', phpfeedback);instead