【发布时间】:2015-12-18 15:22:56
【问题描述】:
我在使用 ajax + php 上传带有图像的信息时遇到问题。尝试添加 dataResult.file = form_data; 时收到非法调用消息正如您在下面的代码中看到的那样。
我将不胜感激任何帮助!我非常坚持这一点,并且已经在 stackoverflow 上搜索了很多可以帮助我的答案。
function uploadImage (upFile,userId,description,category) {
console.log("We have reached the point where we connect to the service to upload the image...");
var dataResult = {};
var form_data = new FormData();
form_data.append('file',upFile[0]);
console.log("Is the information on the form data variable?");
console.log(form_data);
dataResult.file = form_data;
dataResult.idUser = userId;
dataResult.description = description;
dataResult.nameCat = category;
console.log("Description " + dataResult.description);
console.log("Id User " + dataResult.idUser);
console.log("name Cat " + dataResult.nameCat);
console.log("This is the information that is being sent thorugh ajax");
console.log(dataResult);
$.ajax({
url: 'http://localhost/App/www/classes/actionsPhotos/uploadPhoto.php',
type: 'post',
data: dataResult,
success: function (data) {
console.log("All is good and working.");
console.log(data);
},
error: function(errorInfo){
console.log("There was an error: ");
console.log(errorInfo);
}
});
}
【问题讨论】:
标签: javascript php jquery ajax file-upload