2014-11-14 3 views
-1

jQuery와 Ajax를 사용하여 파일을 업로드하려고합니다. 지금까지 모든 것을 클라이언트 측에서 말할 수 있습니다. 나는 파일이 게시되고 모든 것이 (방화 광 콘솔을 사용하여) 볼 수 있지만 서버 측에서는 아무것도 수신하지 못한다는 것을 알 수 있습니다.Ajax를 사용하여 파일 업로드 - 서버 측에서 아무것도 수신하지 않음

var form_data = new FormData($('#share-music-form')[0]); 
 
\t $.ajax({ 
 
\t \t type: 'post', 
 
\t \t url: window.baseurl+'/feeds/ajax/save_music/', 
 
\t \t data: form_data, 
 
\t \t success: function() { 
 
\t \t \t console.log('file DONE!'); 
 
\t \t }, 
 
\t \t xhrFields: { 
 
\t \t \t // add listener to XMLHTTPRequest object directly for progress (jquery doesn't have this yet) 
 
\t \t \t onprogress: function (progress) { 
 
\t \t \t \t // calculate upload progress 
 
\t \t \t \t var percentage = Math.floor((progress.total/progress.totalSize) * 100); 
 
\t \t \t \t // log upload progress to console 
 
\t \t \t \t console.log('progress', percentage); 
 
\t \t \t \t if (percentage === 100) { 
 
\t \t \t \t \t console.log('DONE!'); 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t }, 
 
     error: function(jqXHR, status, error){ 
 
\t \t  console.log(jqXHR); 
 
\t \t  console.log(status); 
 
\t \t  console.log(error); 
 
\t  }, 
 
\t \t processData: false, 
 
\t \t contentType: file.type 
 
\t });
<form action="" method="post" id="share-music-form" enctype="multipart/form-data"> 
 
\t \t \t <label class="fileContainer"> 
 
\t \t \t \t <input type="file" name="text" id="music-file" /> 
 
\t \t \t </label> 
 

 
\t \t \t <input type="text" name="status" id="status-music" class="pic-textarea"> 
 
\t \t </form>

서버 측 :

어레이 (텍스트 출력

print_r($_REQUEST); 
print_r($_FILE); 

=> 텍스트 이 디스플레이마다 코드 내가 게시했습니다) 배열()

+0

AJAX 호출에서 되돌아 오는 오류를 처리하십시오. 이렇게하면 일이 예상대로 작동하는지 확인할 수 있습니다. – melancia

+0

오류 처리를 추가하여 아무 효과가 없습니다. –

+0

어떤 브라우저를 사용하고 있습니까? – SNAG

답변

0

마침내 나는 그것을 작동시킬 수 있었다. 문제는 이전에 file.type으로 설정 한 contentType으로 인한 것 같습니다.
false으로 설정하면 문제가 해결 된 것으로 보입니다.

관련 문제