jQuery上傳外掛程式Uploadify出現Http Error 302錯誤解決

來源:互聯網
上載者:User

標籤:http   io   ar   os   使用   sp   for   on   div   

前段時間介紹過jquery uploadify上傳外掛程式的使用方法,我在使用中遇到過Http Error 302錯誤問題,應該會有很多人在使用中遇到過,在此記錄下來:
首 先http 302是請求被重新導向的意思,這就很容易理解了,如果你的uploadify處理上傳指令碼有session驗證,就會出現此錯誤,因為flash在執行 post請求的時候沒有包含cookie資訊,而伺服器的session會根據用戶端的cookie來得到SESSIONID。沒有提交cookie自然 就不能擷取到session,然後uploadify就返回了302(請求被重新導向)的錯誤。
解決辦法當然是把session_id的值傳到服務端:

<script>$(document).ready(function() {       $(‘#file_upload‘).uploadify({         ‘uploader‘  : ‘uploadify/uploadify.swf‘,         ‘script‘    : ‘uploadify.php‘,        ‘folder‘    : ‘uploads/file‘,         ‘formData‘: { ‘session‘: ‘<?php echo session_id();?>‘},         ‘onComplete‘  : function(event, ID, fileObj, response, data) {           alert(response);         }       }); }); </script>                       複製代碼       



然後在伺服器端session驗證之前:

if (isset($_POST[‘session‘])){     session_id($_POST[‘session‘]);     session_start();//注意此函數要在session_id之後 }                        複製代碼       



當然,你也可以直接在url中將session id傳過去。

jQuery上傳外掛程式Uploadify出現Http Error 302錯誤解決

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.