0

如何将 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();
    });
4

1 回答 1

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();});
于 2012-04-09T09:01:05.223 回答