我的javascript包含此对话框,其中包含文件和隐藏的输入,如此
form1 = form1 +
"<form enctype='multipart/form-data' action='svScheckPicOtc' accept-charset='utf-8' id='formOTCSCImgUpld' method='post'>" +
"<input id='fileImageGroup' name='fileImageGroup' type='file' class='globaltextbox' />" +
"<div id='divResultImgGroup'>" + "<table border='0'><tr><td><div style='height:100px; width:100px; border: 1.8px solid #CCCCCC;'></div></td></tr></table>" + "</div>" +
"<input id='hidThr_InvNo' name='hidThr_InvNo' type='hidden' value='" + InvNo + "' />" +
"</form><br>";
这是我的ajax
$('#formOTCSCImgUpld').ajaxForm({
beforeSubmit: function() {
var percentVal = '0%';
bar.width(percentVal);
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal);
percent.html(percentVal);
},
success: function(retData) {
alert(retData);
var percentVal = '100%';
bar.width(percentVal);
percent.html(percentVal);
preventDoubleUpload = 1;
var retDataSplit = retData.split(":=:");
if (retDataSplit[0] == "validationerrors")
{
for (a=1;a < genFieldResets.length;a++)
{
$("#" + genFieldResets[a]).css({"color":"#000000"});
$("#" + genFieldResets[a]).css({"font-weight":"normal"});
}
var errorText = "";
for (a=1;a < retDataSplit.length;a++)
{
if (retDataSplit[a] == "error_1")
{
errorText = errorText + "<li><span style='color:red;'><b>Invalid File or No file selected.</b></span></li>";
}
else if (retDataSplit[a] == "error_2")
{
errorText = errorText + "<li><span style='color:red;'><b>File size should not exceed 5MB.</b></span></li>";
}
else if (retDataSplit[a] == "error_3")
{
errorText = errorText + "<li><span style='color:red;'><b>Invalid File Format. Please Upload JPG/JPEG image only.</b></span></li>";
}
else if (retDataSplit[a] == "error_4")
{
errorText = errorText + "<li><span style='color:red;'><b>Invalid File Extension Name. Please Upload JPG/JPEG image only.</b></span></li>";
}
else if (retDataSplit[a] == "error_5")
{
errorText = errorText + "<li><span style='color:red;'><b>You already uploaded an image. Remove the image first in order to upload a new one.</b></span></li>";
}
else
{
$("#" + retDataSplit[a]).css({"color":"#FF0000"});
$("#" + retDataSplit[a]).css({"font-weight":"600"});
}
}
if (errorText == "")
{
<!-- altClosePopBox(); -->
openPUBox("exsmall");
$("#popbox500x150_content").html(pboxcovers("exsmall") + "<b>You need to Fill-up all the Required Fields correctly to continue.</b>" + "</div>");
}
else
{
<!-- altClosePopBox(); -->
openPUBox("small");
$("#popbox500x300_content").html(pboxcovers("small") + "You have an error in this fields:<br><ul>" + errorText + "</ul>" + "</div>");
}
js1101_pboxCloseButtonLock = 1;
genFieldResets.length = 0;
genFieldResets = retDataSplit;
}
else if (retDataSplit[0] == "success")
{
$("#divResultImgGroup").html(retDataSplit[1]);
$("#fileImageGroup").val('');
<!-- altClosePopBox(); -->
}
},
error: function(requestObject, error, errorThrown){
console.log(requestObject);
console.log(error + ": " + errorThrown);
}
});
但是,每当我在onChange
上提交input[type='file']
事件触发的表单时,我总是会收到错误500.当我将方法更改为get
时,不会抛出任何错误。但绝对不会上传文件。
请注意,我正在使用CodeIgniter,这种结构完全适用于view
。我想要做的是在对话框/弹出窗口中实现它。
答案 0 :(得分:1)
您的500错误可能来自问题服务器端。你在codeigniter中得到任何错误吗?