2012-04-09 30 views
0

如何將ajaxStart/ajaxStop綁定到窗體?如何將ajaxStart/ajaxStop綁定到表單?

我需要一個裝載模塊,顯示上載

現在的形式是不是在所有

var iframe = $('<iframe name="iframe_file_upload" src="'+src_file_upload+'" style="display:none"></iframe>'); 
var btn_send = $('<input type="button" />') 
    .click(function(){ 
     $('#form_upload_file').bind('ajaxStart', function(){ 
      $(this).submit(); 
     }); 
     iframe.bind('ajaxStop', function(){ 
      $(this).load(function(){ 
       ... 

更新

var btn_send = $('<input type="button" />') 
    .click(function(){ 
     $('#form_upload_file').ajaxForm(
      $('#form_upload_file').ajaxForm({ 
       success : function(response){ 
        // the response is a string?! how can the response be retrieved as an JSON object? 
        alert(response); 
       } 
      } 
     }).submit(); 
    }); 
+0

嘗試'$(「#提交的文件form_upload_file「)。ajaxStart(function(){ iframe.show(); });' – diEcho 2012-04-09 08:35:07

+0

該iframe必須保持隱藏..該文件是從iframe – clarkk 2012-04-09 08:36:18

+0

上傳你想要顯示然後? – diEcho 2012-04-09 08:37:53

回答

0
//initially hide your loading block 
$('#loadingblock').hide(); 

//submit form using ajax-request 
$('#yourform').submit(function(){ 
$.post('formhandle.php',$(this).serialize(),function(){alert('form submitted!')}); 
//prevent default submission 
return false; 
} 

//now the loader part 
$('#loadingblock').ajaxStart(function(){$(this).show();}) 
.ajaxStop(function(){$(this).hide();}); 
+0

如果你不想這樣做表單提交,然後更改事件提交點擊或其他。而不是序列化,發送您的文件輸入數據。 – 2012-04-09 09:07:42