2012-08-31 41 views
0

這是一個很好的小ajax上傳代碼片段,它將通過ajax在成功上傳或文件時返回消息太大......諸如此類的事情。在upload.php Iis中,我有包含返回到表單頁面的消息的div。我想知道如何修改它,以便divs /消息返回到模態窗口,而不是僅僅返回到頁面本身...希望有人可以幫助我。我需要在某處使用jQuery UI嗎?多謝你們!通過jquery返回AJAX消息到一個模式窗口

 $j(document).ready(function(){ 
var upload = new AjaxUpload('#userfile', { 
     //upload script 
     action: '/modules/mod_artuploader/upload.php', 
     onSubmit : function(file, extension){ 
     //show loading animation 
     //$j("#loading").show(); 
     //check file extension 
     if (! (extension && /^(jpg|png|jpeg|gif)$/.test(extension))){ 
     // extension is not allowed 
      $j("#loading").hide(); 
      $j("<span class='error'>Error: Not a valid file extension</span>").appendTo("#file_holder #errormes"); 
      // cancel upload 
     return false; 
      } else { 
       // get rid of error 
      $j('.error').hide(); 
      } 
      //send the data 
      upload.setData({'file': file, 'userid': <?php echo $user->id?> }); 
     }, 
     onComplete : function(file, response){ 
     //hide the loading animation 
     $j("#loading").hide(); 
     $j("#userfile").hide(); 
     $j('label[for="userfile"]').hide(); 
     //add display:block to success message holder 
     $j(".success").css("display", "block"); 
     $j(".picture").css("display", "block"); 
     //This lower portion gets the error message from upload.php file and appends it to our specifed error message block 
     //find the div in the iFrame and append to error message  
     var oBody = $j(".iframe").contents().find("div"); 
     //add the iFrame to the errormes td 
     $j(oBody).appendTo("#file_holder #errormes"); 

} 
    }); 
}); 
     </script> 

回答

0

這真的取決於你使用的模式。如果您正在討論單獨的瀏覽器窗口,浮動解除鎖定或新選項卡,那麼這是一個非常複雜的問題。既然你提到了,jQuery UI對話框是一個很好的選擇。看看modal form的例子。用戶可以點擊一個'上傳'按鈕,用文件選擇器激活模式彈出窗口。您可以切換顯示對話框$(foo).dialog('open')$(foo).dialog('close')。然後,上傳腳本就可以存在於對話框中並與其中的元素進行交互。至少,我認爲你的回調將能夠通過appendTo調用對話框。你可能最終需要做的是打開一個上傳對話框,等待響應,然後關閉它並打開另一個結果。

相關問題