如何将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 :(得分: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();});