簡體   English   中英

fine-uploader無法使用IE7讀取iframe響應

[英]fine-uploader can't read iframe response with IE7

我正在服務器端使用jquery.fineuploader-3.7.0和Code igniter框架。

我的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'); });

我的服務器端響應是:

>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

內容:

{"success":true,"file_inner":"<a href='pj\/'116810_116810_cimpa_insertion.xls'  target='_blank'>116810_cimpa_insertion.xls<\/a>"}

在FF下,Chrome瀏覽器在我的網頁上(綠色)顯示成功消息,但在IE7或IE8下,我在調試欄控制台中顯示了一條消息:

[FineUploader 3.7.0]嘗試解析iframe上載響應時出錯([對象錯誤])[FineUploader 3.7.0]'錯誤'不是服務器響應上的有效屬性。

和網頁錯誤消息(紅色)。 但是上傳正常(文件在我的服務器上正確)

我是初學者,需要精打細算,能幫我找出我在哪里出錯嗎?

服務器端代碼:

/**
* 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 );
  }

更新:我進行更改后,我的服務器響應:

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

和內容:

{"success":true,"file_inner":"<a href=\"pj\/116842_116842_brochure 12.pdf\"  target=\"_blank\">116842_brochure 12.pdf<\/a>"}

我總是有一條紅色的網絡消息,說:上傳失敗(法語),並且此消息在調試欄控制台中:

[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.

非常感謝您的幫助

斯特凡

更改內容類型后,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

內容 :

{"success":true,"file_inner":"<a href=\"pj\/116841_116841_capture_portail_sonacotra.doc\"  target=\"_blank\">116841_capture_portail_sonacotra.doc<\/a>"}

我認為這不是內容的問題,也許是IE的問題,它無法讀取iframe上服務器發送的響應,但是我對JavaScript不夠了解,無法找到解決方案

2013年7月29日更新:我進行了測試:如果我刪除$ return ['file_inner']並且我僅保留成功或錯誤消息,那么就可以了

我的$ return ['file_inner']就在這里,因為用戶可以通過單擊鏈接來驗證文檔上傳。 但這不是一個很重要的功能,我可以刪除它。 當它們是我的對象“響應”中的多屬性時,也許我忘記了一些東西。 或上傳者代碼不錯,只能等待一個屬性。

仔細研究之后,您的JSON響應會有一些奇怪的屬性。

我對PHP的專業經驗很少,但是我可以說您的回復內容不正確。 您可能應該使用json_encode格式化響應內容。 Fine Uploader 的示例PHP腳本已經做到了。 也許你應該看看。

無論哪種方式,您的響應內容都應如下所示:

{"success":"true","file_inner":"<a href=\"pj/116841_116841_capture_portail_sonacotra.doc\"  target=\"_blank\">116841_capture_portail_sonacotra.doc</a>"}

由OP解決。

解決方案是在示例php腳本中,我的錯誤是在沒有htmlspecialchars轉換的情況下在我的對象中創建了一個url。 在服務器端使用此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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM