In my Codeigniter 2.2
project I am trying to upload image using ajax
and codeigniter inbuilt file upload
. File upload is working good. But my issue is, I can see only some encrypted text at the response field of the browser.
在我的Codeigniter 2.2项目中,我尝试使用ajax和Codeigniter内建文件上传图片。文件上传运行良好。但我的问题是,我只能在浏览器的响应域中看到一些加密的文本。
The problem is only with firefox
browser. It is working with google chrome
问题只在于firefox浏览器。它使用的是谷歌chrome浏览器
So that I can't debug the errors. I cannot find the error at all. How can I avoid this? Any help could be appreciated
这样我就不能调试错误了。我根本找不到错误。我怎样才能避免这种情况呢?任何帮助都是值得感激的
ajax call
ajax调用
$('#myForm').submit(function(e) {
e.preventDefault();
var data = new FormData(this);
$.ajax({
url: page_url,
type: 'POST',
dataType: 'json',
data: data,
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
success: function(data) {
alert(data);
},
error: function() {
alert('error');
}
});
});
the text in the browser response field
浏览器响应字段中的文本
PGRpdiBzdHlsZT0iYm9yZGVyOjFweCBzb2xpZCAjOTkwMDAwO3BhZGRpbmctbGVmdDoyMHB4O21hcmdpbjowIDAgMTBweCAwOyI+Cgo8aDQ+QSBQSFAgRXJyb3Igd2FzIGVuY291bnRlcmVkPC9oND4KCjxwPlNldmVyaXR5OiBOb3RpY2U8L3A+CjxwPk1lc3NhZ2U6ICBVbmRlZmluZWQgb2Zmc2V0OiAyPC9wPgo8cD5GaWxlbmFtZTogbWFzdGVyL21hc3RlcnNfY3RyLnBocDwvcD4KPHA+TGluZSBOdW1iZXI6IDY2MDwvcD4KCjwvZGl2PjxkaXYgc3R5bGU9ImJvcmRlcjoxcHggc29saWQgIzk5MDAwMDtwYWRkaW5nLWxlZnQ6MjBweDttYXJnaW46MCAwIDEwcHggMDsiPgoKPGg0PkEgUEhQIEVycm9yIHdhcyBlbmNvdW50ZXJlZDwvaDQ+Cgo8cD5TZXZlcml0eTogTm90aWNlPC9wPgo8cD5NZXNzYWdlOiAgVW5kZWZpbmVkIG9mZnNldDogMTwvcD4KPHA+RmlsZW5hbWU6IG1hc3Rlci9tYXN0ZXJzX2N0ci5waHA8L3A+CjxwPkxpbmUgTnVtYmVyOiA2NjI8L3A+Cgo8L2Rpdj57Im1zZyI6IiIsImVycm9yIjoiRmFpbGVkIHRvIEFkZCBQZW5zaW9uZXIgRGV0YWlscyIsImVycm9yX21lc3NhZ2UiOiIifQ==
1 个解决方案
#1
3
You have to create and push that file into FormData like this :
您必须创建并推动该文件到FormData如下:
$('#myForm').submit(function(e) {
e.preventDefault();
var data = new FormData(this);
var fileObj = $('#imagefileUpload').get(0); // input type file element
var img, reader, file;
file = fileObj.files[0];
/*match type of file*/
if (!!file.type.match(/image.*/)) {
if (window.FileReader) {
reader = new FileReader();
reader.onloadend = function(e) {
};
reader.readAsDataURL(file);
}
if (data) {
data.append('imagefileupload', file);
}
}
$.ajax({
url: page_url,
type: 'POST',
dataType: 'json',
data: data,
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
success: function(data) {
alert(data);
},
error: function() {
alert('error');
}
});
});
#1
3
You have to create and push that file into FormData like this :
您必须创建并推动该文件到FormData如下:
$('#myForm').submit(function(e) {
e.preventDefault();
var data = new FormData(this);
var fileObj = $('#imagefileUpload').get(0); // input type file element
var img, reader, file;
file = fileObj.files[0];
/*match type of file*/
if (!!file.type.match(/image.*/)) {
if (window.FileReader) {
reader = new FileReader();
reader.onloadend = function(e) {
};
reader.readAsDataURL(file);
}
if (data) {
data.append('imagefileupload', file);
}
}
$.ajax({
url: page_url,
type: 'POST',
dataType: 'json',
data: data,
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
success: function(data) {
alert(data);
},
error: function() {
alert('error');
}
});
});