2014-11-12 2 views
0

와 현재 데이터를 전달 나는 이미지를 업로드하는 데 사용하는 양식이ajaxform

var statustxt    = $('#statustxt'); 
     var submitbutton   = $("#SubmitButton"); 
     var myform     = $("#UploadForm"); 
     var galleryStatus2$   = $("#galleryStatus2"); 
     var error_code; 


     $(myform).ajaxForm({ // called when the code loads 
      data : {dstDir : g.currentGal}, // pass in some $_POST parameters 
      resetForm : true, 
      beforeSend: function() { //before submitting the form 
       galleryStatus2$.empty(); // clear status from last upload 
       submitbutton.attr('disabled', ''); // disable upload button 
       $('img#loadGif').fadeIn(200);  // start spinner 
      }, 
      complete: function(response) { // upload complete 
       console.log("<br />upload complete. g.currentGal = " + g.currentGal); 
       galleryStatus2$.html(response.responseText); //upload status 
       submitbutton.removeAttr('disabled'); //enable submit button again 
       $('img#loadGif').fadeOut(200);  // kill spinner 

제가하는 데 문제는 내가 원하는 것입니다 액션 스크립트 uploadImage.php에 업로드 할 디렉토리를 알릴 수 있어야합니다. 나는 이것을 "data : {dstDir : g.gurrentGal}"라인으로 시도한다. g.currentGal은 마지막으로 더블 클릭 된 폴더, 즉 마지막으로 열렸던 폴더를 저장하므로 업로드 할 대상이됩니다. 그러나 양식이 제출 될 때가 아니라 코드가 처음로드 될 때 ajaxform 코드가 실행됩니다. 따라서 g.currentGal은 JavaScript가 처음으로로드 될 때 변수가 초기화 된 이후의 마지막 폴더는 절대로 초기화되지 않습니다. $ _POST 배열의 uploadImage.php로 양식이 제출 될 때 g.currrentGal의 가치를 얻으려면 어떻게해야합니까?

감사합니다.

답변

0

입력 사항을 삭제하고 버튼을 대신 입력해야합니다. 버튼을 클릭하면 정보가 숨겨진 입력 태그 안에 저장됩니다. 그런 다음 (jquery 또는 기타를 사용하여) 양식을 제출할 수 있습니다. 그러면 html 양식을 사용하여 PHP 페이지에서 설정 한 매개 변수를 얻을 수 있습니다.

편집 : 폴더를 열 때마다 양식을 제출하기 전에 g.storeFolder를 다시 실행하십시오.

관련 문제