【发布时间】:2013-12-10 18:39:37
【问题描述】:
我正在使用Uploadifive 上传插件。它可以正常工作。但是,我很难通过插件将 error 和 success 消息从我的控制器传递回我的视图。我正在记录控制台和log 错误。但似乎无法将任何控制器错误返回到 Uploadifive 调用以显示在我的视图中。
简而言之,我想从我的控制器(通过$result var)将error 或success 消息输出回我的ajax 函数以嵌入到我的视图中。
警报alert(data.result) 输出“未定义”。
JS函数:
$('#file-upload').uploadifive({
...
'onUpload': function(file) {
console.log('upload complete!');
},
'onUploadComplete' : function(file, data) {
console.log('The file ' + file.name + ' uploaded successfully.');
// returned error/success message here
alert(data.result);
},
'onError': function(errorType) {
console.log(errorType);
}
});
CI 控制器方法:
function add_document() {
// If Ajax request, proceed:
if(isset($_POST['is_ajax'])) {
if (!$this->upload->do_upload()) {
// If file upload failed or is invalid,
// display error notification
$result = array('error' => $this->upload->display_errors());
echo json_encode($result);
}
else {
// If file upload was successful
$result = 'success!';
echo $result;
...
}
}
// if not, redirect to upload page
else {
redirect('upload');
}
}
【问题讨论】:
-
你的控制台得到了什么?
-
只是
console.logjs 中详述的(这很好)。没有其他错误。警报虽然 (alert(data.result);) 输出“未定义”。 -
Ok console.log 数据和文件在你的上传完成功能,我去喝杯咖啡,然后我们会粉碎这个。
-
当我了解 Uploadifive 与 Uploadify 时,我发现这个脚本不是免费的,而且他们的文档很糟糕(不包含任何关于服务器响应的内容) - 我认为您需要更多的控制台调试。
-
是的,你也可以想象我的沮丧,哈哈。不确定我可以运行哪些其他调试...如果您需要上传 src,请通过电子邮件发送给我。我向您发送“付费”版本没有问题。 :D
标签: php jquery ajax codeigniter uploadify