[英]fine-uploader can't read iframe response with IE7
I'm using the jquery.fineuploader-3.7.0 and Code igniter framework for the server side. 我正在服务器端使用jquery.fineuploader-3.7.0和Code igniter框架。
My js code : 我的js代码:
$('#manual-fine-uploader').fineUploader({
request : { endpoint: 'declaration/uploadfile'},
autoUpload : false,
template : '<div class="qq-uploader span12">' +
' <pre class="qq-upload-drop-area span12"><span>{dragZoneText}</span></pre>' +
' <div class="qq-upload-button " style="width: auto;">{uploadButtonText}</div>' +
' <span class="qq-drop-processing"><span>{dropProcessingText}</span><span class="qq-drop-processing-spinner"></span></span>' +
' <ul id="qq-upload-list" class="qq-upload-list" style="margin-top:10px; text-align:center;"><li></li></ul>' +
' <ul class="qq-upload-list" style="margin-top: 10px; text-align: center;"></ul>' +
'</div>',
fileTemplate : '<li>' +
' <div class="qq-progress-bar"></div>' +
' <span class="qq-upload-spinner"></span>' +
' <span class="qq-upload-finished"></span>' +
' <span class="qq-upload-file"></span>' +
' <span class="qq-upload-size"></span>' +
' <a class="qq-upload-cancel" href="#">{cancelButtonText}</a>' +
' <a class="qq-upload-retry" href="#">{retryButtonText}</a>' +
' <a class="qq-upload-delete" href="#">{deleteButtonText}</a>' +
' <span class="qq-upload-status-text">{statusText}</span>' +
'</li>',
failedUploadTextDisplay : {
mode : 'custom',
maxChars : 1500,
responseProperty : 'error',
enableTooltip : true
},
text : {
uploadButton : '<color=#2E6E9E><b>Selectionnez le fichier à déposer</b></color>',
failUpload : 'Le chargement a échoué'
} });
$('#triggerUpload').click(function() {
$('#manual-fine-uploader').fineUploader('setParams', {'id_fait':$('#id_fait').attr('value') });
$('#manual-fine-uploader').fineUploader('uploadStoredFiles'); });
My server side response are : 我的服务器端响应是:
>HTTP/1.0 200 OK
>Date: Fri, 26 Jul 2013 08:12:09 GMT
>Server: Apache/2.2.15 (CentOS)
>X-Powered-By: PHP/5.3.3
>Expires: Thu, 19 Nov 1981 08:52:00 GMT
>Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
>Pragma: no-cache
>Connection: close
>Content-Type: text/html; charset=UTF-8
content : 内容:
{"success":true,"file_inner":"<a href='pj\/'116810_116810_cimpa_insertion.xls' target='_blank'>116810_cimpa_insertion.xls<\/a>"}
Under FF, Chrome i have a sucess message on my web page (the green) but under IE7 or IE8 i have a message who said in my debug bar console: 在FF下,Chrome浏览器在我的网页上(绿色)显示成功消息,但在IE7或IE8下,我在调试栏控制台中显示了一条消息:
[FineUploader 3.7.0] Error when attempting to parse iframe upload response ([object Error]) [FineUploader 3.7.0] 'error' is not a valid property on the server response. [FineUploader 3.7.0]尝试解析iframe上载响应时出错([对象错误])[FineUploader 3.7.0]'错误'不是服务器响应上的有效属性。
and web page error message(the red ). 和网页错误消息(红色)。 But the upload are ok (the file are correctly on my server)
但是上传正常(文件在我的服务器上正确)
I'm a beginner under fine-uploader, could you help me to find where i have make an error please ? 我是初学者,需要精打细算,能帮我找出我在哪里出错吗?
code of the server side: 服务器端代码:
/**
* uploadfile
* @access public
* @return string
*/
public function uploadfile() {
$post['id_fait'] = $this->input->post('id_fait');
if ( empty($post['id_fait']) ) {
$return['error'] = 'ID_FAIT manquant';
return true;
}
else {
$_FILES['qqfile']['name'] = $post['id_fait']."_".$_FILES['qqfile']['name'];
$config['upload_path'] = DOCUMENT_PATH;
$config['max_size'] = UPLOAD_MAX_SIZE;
$config['overwrite'] = FALSE;
$config['allowed_types'] = ALLOWED_EXT;
$config['remove_spaces'] = FALSE;
$this->load->library('upload', $config);
if ( !$this->upload->do_upload('qqfile')) { $return['error'] = $this->upload->error_msg[0]; }
else {
$data = $this->upload->data();
$post['fichier'] = $data['file_name'];
$insert = $this->db->insert('senla_faits_piece_jointe',$post);
$return['success'] = $insert;
$return['file_inner'] = "<a href='pj/'".$post['id_fait']."_".$data['file_name']."' target='_blank'>".$data['file_name']."</a>";
}
}
echo json_encode( $return, JSON_FORCE_OBJECT );
}
UPDATE : After i make the change my server response : 更新:我进行更改后,我的服务器响应:
HTTP/1.0 200 OK
Date: Fri, 26 Jul 2013 20:21:01 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 124
Connection: close
Content-Type: text/html; charset=UTF-8
and the content : 和内容:
{"success":true,"file_inner":"<a href=\"pj\/116842_116842_brochure 12.pdf\" target=\"_blank\">116842_brochure 12.pdf<\/a>"}
I have always a red web message who said : upload fail (in french) and this message in my debug bar console : 我总是有一条红色的网络消息,说:上传失败(法语),并且此消息在调试栏控制台中:
[FineUploader 3.7.0] Error when attempting to parse iframe upload response ([object Error])
[FineUploader 3.7.0] 'error' is not a valid property on the server response.
Thank a lot for your help 非常感谢您的帮助
Stéphane 斯特凡
Update 2 after change the content type, always the same problem : The server response : 更改内容类型后,Update 2始终存在相同的问题:服务器响应:
HTTP/1.0 200 OK
Date: Sat, 27 Jul 2013 20:14:38 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=7riosh2q9edldanjp9vtg4ili3; path=/
Set-Cookie: PHPSESSID=7riosh2q9edldanjp9vtg4ili3; path=/
Connection: close
Content-Type: text/plain; charset=UTF-8
The content : 内容 :
{"success":true,"file_inner":"<a href=\"pj\/116841_116841_capture_portail_sonacotra.doc\" target=\"_blank\">116841_capture_portail_sonacotra.doc<\/a>"}
I think it's not a problem of content, perhaps it's a problem of IE who can't read the response send by the server across the iframe, but i don't know sufficiently the javascript to find the solution 我认为这不是内容的问题,也许是IE的问题,它无法读取iframe上服务器发送的响应,但是我对JavaScript不够了解,无法找到解决方案
UPDATE 29/07/2013 : I have make a test : If i delete my $return['file_inner'] And i keep only the sucess or error message then that's ok 2013年7月29日更新:我进行了测试:如果我删除$ return ['file_inner']并且我仅保留成功或错误消息,那么就可以了
My $return['file_inner'] are just here because user could be verify the document upload by clicking on the link. 我的$ return ['file_inner']就在这里,因为用户可以通过单击链接来验证文档上传。 But it's not a very important fonction, i could delete it.
但这不是一个很重要的功能,我可以删除它。 Perhaps i have forget something when they are severals attributes in my object "response".
当它们是我的对象“响应”中的多属性时,也许我忘记了一些东西。 or perhaps fine uploader code wait only one attribut.
或上传者代码不错,只能等待一个属性。
After having a closer look, there are a few odd properties of your JSON response. 仔细研究之后,您的JSON响应会有一些奇怪的属性。
I have very little professional experience with PHP, but I can say that your response content is not correct. 我对PHP的专业经验很少,但是我可以说您的回复内容不正确。 You should probably be using
json_encode
to format your response content. 您可能应该使用
json_encode
格式化响应内容。 Fine Uploader has an example PHP script that already does this. Fine Uploader 的示例PHP脚本已经做到了。 Perhaps you should have a look.
也许你应该看看。
Either way, your response content should look like this: 无论哪种方式,您的响应内容都应如下所示:
{"success":"true","file_inner":"<a href=\"pj/116841_116841_capture_portail_sonacotra.doc\" target=\"_blank\">116841_capture_portail_sonacotra.doc</a>"}
Solution by OP. 由OP解决。
The solution are in the example php script, my error are to make a url in my object without the htmlspecialchars conversion. 解决方案是在示例php脚本中,我的错误是在没有htmlspecialchars转换的情况下在我的对象中创建了一个url。 With this php code on the server side it's OK
在服务器端使用此php代码就可以了
/**
* uploadfile
* @access public
* @return string
*/
public function uploadfile() {
$post['id_fait'] = $this->input->post('id_fait');
if ( empty($post['id_fait']) ) {
$return['error'] = 'ID_FAIT manquant';
return true;
}
else {
$_FILES['qqfile']['name'] = $post['id_fait']."_".$_FILES['qqfile']['name'];
$config['upload_path'] = DOCUMENT_PATH;
$config['max_size'] = UPLOAD_MAX_SIZE;
$config['overwrite'] = FALSE;
$config['allowed_types'] = ALLOWED_EXT;
$config['remove_spaces'] = FALSE;
$this->load->library('upload', $config);
if ( !$this->upload->do_upload('qqfile')) { $return['error'] = $this->upload->error_msg[0]; }
else {
$data = $this->upload->data();
$post['fichier'] = $data['file_name'];
$insert = $this->db->insert('senla_faits_piece_jointe',$post);
$return['success'] = $insert;
$return['file_inner'] = "<a href=\"pj/".$post['id_fait']."_".$data['file_name']."\" target=\"_blank\">".$data['file_name']."</a>";
}
}
// log_askel($this->upload);
header('Content-type: text/plain');
echo htmlspecialchars(json_encode($return), ENT_NOQUOTES);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.