2012-05-25 5 views
1

jqgrid 및 ajaxFileUpload.js 스크립트를 사용하여 매개 변수와 파일을 PHP 스크립트에 전달합니다. 코드의 구조는 다음과 같다 :dilemna with jqgrid and ajaxfileupload

... 
url:url_1.php, 
beforeSubmit: function (postdata,formid) 
    { 
     $.ajaxFileUpload ( 
     { 
      url: url_2.php, 
      ... 
      success: 
      error:  
     }), 
     return[true,""]; 
    }, 
afterSubmit: function(reponse,postdata) 
    { 
     ... 
     return [true,'','']; 
    } 

나는이 딜레마가 다음있는 jqGrid 행동에 따르면
을 url_2.php가 url_1.php 다음이라고합니다.
url_2.php는 데이터 (매개 변수 + 파일)를 처리하고, url_1.php는 아무 것도 처리하지 않습니다.
url_2.php가 오류 또는 메시지를 반환 할 수 있지만 (예 : '이미 있음') 오류는 aftersubmit 이벤트에 의해 양식에 표시되며이 이벤트는 url_1.php에서 오류를받습니다.
나는 beforesubmit 이벤트에 ajaxfileupload를 넣어야한다고 생각한다.
이 딜레마를 해결하기위한 아이디어가 있습니까?

답변

0

대신 jquery form plugin 및 jqGrid dataProxy 메소드를 사용할 수 있습니다.

useDataProxy: true, 
    dataProxy : function (opts, act) { 

    opts.iframe = true; 
    var $form = $('#FrmGrid_' + $grid.jqGrid('getGridParam', 'id')); 
    //Prevent non-file inputs double serialization 
    var ele = $form.find('INPUT,TEXTAREA,SELECT').not(':file'); 
    ele.each(function() { 
     $(this).data('name', $(this).attr('name')); 
     $(this).removeAttr('name'); 
    }); 

    //Send only previously generated data + files 
    $form.ajaxSubmit(opts); 
    //Set names back after form being submitted 
    setTimeout(function() { 
     ele.each(function() { 
      $(this).attr('name', $(this).data('name')); 
     }); 
    }, 200); 
}; 

예 : http://jqgrid-php.net file fileUpload 클래스는 이것을 사용합니다. 이는 How to force dataProxy call in form editing if editurl is set in jqgrid에도 설명되어 있습니다.

+0

dataproxy가 jqgrid 위키에 없습니다! – Bertaud

+0

왜 결국 setTimeout? – Bertaud