Jquery加载动画与PHP表单提交回自己


jquery loading animation with php form that submits back to itself

我有一个PHP文件,其中包含一个表单,并提交回自己。是否有任何方法显示加载动画后,表单提交和运行,直到页面加载?

如果你想在表单提交时显示进度指示器,为什么不使用AJAX?

$("form").submit(function(e) {
    e.preventDefault();
$(".loading").show();//Assuming you have a container which has appropriate style and image to show the loading image
    $.post( {
       url: $(this).attr("action"), 
       data: $(this).serialize(),
       success: function(){ 
           $(".loading").show();
           //Write code here to handle on success 
        }
    });
});

这是微不足道的。假设你在页面的某个地方有一个隐藏的旋转器/加载图像,id为'loadingImg':

$("form").submit(function() {
    $("#loadingImg").show();
});

演示:http://jsfiddle.net/yFaAj/1/