2012-05-14 34 views
-1

我在執行加載程序gif時遇到了一些問題,我的表單正在提交到另一個頁面,處理器頁面。這是代碼:加載程序gif工具

形式:前搜索結果中顯示

<form name="myform" id="myform" action="" method="POST"> 
<!-- The Name form field --> 
<div align='center'> 


<form name="myform" id="myform" action="" method="POST"> 
<!-- The Name form field --> 
<font face='candara' size='3' color='#6382A1'>Ime ili prezime:</font> 
    <input type="text" name="name" id="name" value=""> 

<meta http-equiv="Content-Type" content="text/html; charset=windows-1250" /> 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> 
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
$("#myform").validate({ 
debug: false, 
rules: { 
name: "required", 

}, 
messages: { 
name: "Unesite podatke.", 

}, 
submitHandler: function(form) { 
// do other stuff for a valid form 
$.post('process.php', $("#myform").serialize(), function(data) { 
           $('#results').html(data); 
          }); 
         } 
        }); 
       }); 
       </script> 
       <style> 
label.error { width: 250px; display: inline; color: red; font-family:candara;} 
        </style> 


       <!-- We will output the results from process.php here --> 
       <br><div id="results"></div> 

所以我不知道在哪裏以及如何實現裝載機GIF?

這是裝載機GIF:

<!--LOADER!-->        


<br><div id="loadingGif" style="display:none; background: url(slike_izgled/transparent_loader.png);" align="center"><img src='ajax-loader.gif'> 
<br><font face='candara' size='3'><b>Pretražujem bazu podataka, molim pricekajte...</b></font></div> 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script> 


<script> 

$("form").submit(function(e) { 
//e.preventDefault(); 

$("#loadingGif").show(); 
}); 

</script> 



       <!--LOADER END!--> 
+1

代碼過載。請縮小到您遇到的問題。 – iambriansreed

回答

1
在submitHandler

使用$.ajax代替$.post,你將能夠使用beforeSend

$.ajax({ 
    type : 'post', 
    url : 'your url', 
    data : 'your data', 
    beforeSend : function(){ 
     $('#loadingGif').show(); 
    }, 
    success : function(data){ 
     $('#loadingGif').hide(); 
     // do your stuff here 
    } 

});

+0

是的,然後頁面重新加載,這是我需要顯示所有的問題:加載程序,結果沒有重新加載頁面。 –

+0

在$('#form')。submit()的開頭添加e.preventDefault(),或者在最後返回false? – jbduzan

+0

我已經這樣做了,但現在腳本沒有處理表單。該表格不受限制。可能是我在做這個腳本有問題。 '$阿賈克斯({ \t \t \t \t \t \t類型: '後', \t \t \t \t \t \t網址: 'process.php', \t \t \t \t \t \t數據: '#results', \t \t \t \t \t \t beforeSend:function(){ \t \t \t \t \t \t $('#loadingGif')。show(); 。 \t \t \t \t \t \t}, \t \t \t \t \t \t成功:功能(數據){ \t \t \t \t \t \t $( '#loadingGif')隱藏(); \t \t \t \t \t \t $ .POST( 'process.php',$( 「#myForm會」)。序列(),函數(數據){ \t \t \t \t \t \t \t \t $( '#結果') 。HTML(數據); \t \t \t \t \t \t \t \t}); \t \t \t \t \t \t}' –