2010-11-22 168 views
0
img="loader.gif (editeg link because i need 10 more reps to add img src tag)"; 

var pot=true; 
function trimite(){ 
    if(pot==true){ 
    pot=false; 
    jQuery("#loader").hide().html(img).slideDown(); 
    jQuery("#sec_code").fadeOut("slow"); 
    jQuery("#log_res").slideUp(); 
    jQuery.ajax({ 
    url:"register.php", 
    type:"post", 
    data:'utilizator='+jQuery("#utilizator").val()+'&parola='+jQuery("#parola").val()+'&reparola='+jQuery("#reparola").val()+'&mail='+jQuery("#mail").val()+'&security_code='+jQuery("#security_code_x").val(), 
    success:function(msg){ 
    jQuery("#loader").hide().html(img).slideUp(); 
    jQuery("#log_res").hide().html(msg).slideDown(); 
    jQuery("#sec_code").html('<img style="margin-top: -2px;" src="captcha.php?'+Math.random()+'" />').fadeIn("slow"); 
    pot=true; 
    } 
    }); 
    } else return false; 
} 

形式爲:jQuery的形式提交

編輯的圖片鏈接,不能發佈img標籤

當我點擊提交,我在同一頁頁.php?utilizator = somevalue & pass = somevalue等,它不會在register.php上發出請求。爲什麼,我不知道,在js控制檯上,我無法加載資源,但它存在..它工作了一段時間,但我不知道我修改了什麼所以它不能成功運行.. 乾杯,Edi。

+0

如果無法加載URL,它不存在或路徑是錯誤的。使用Firebug來調試請求 - 除此之外我們還可以做些什麼來幫助我認爲 – 2010-11-22 19:31:45

+0

請顯示錶單的代碼或調用的地方trimite() – Dutchie432 2010-11-22 19:32:19

回答

0
<form onsubmit="javascript: return trimite();"> 
<input name="utilizator" type="text" class="password" id="utilizator" value="" size="32" maxlength="15"> 
<input name="parola" type="password" class="password" id="parola" value="" size="32" maxlength="30"> 
<input name="reparola" type="password" class="password" id="reparola" value="" size="32" maxlength="30"> 
<input name="mail" type="text" class="password" id="mail" value="" size="32" maxlength="40"> 
<img style="margin-top: -2px;" src="captcha.php" alt="ANTI SPAM !"> 
<input name="security_code" type="text" class="password" id="security_code_x" value="" size="5" maxlength="5"> 
<input type="submit" value="Inregistrare"> 
</form> 

這是我用jquery函數提交的表單trimite();我在函數之前加載jquery v1.4.4。

0

您需要return false要麼的情況下,以防止默認提交行爲......這是怎麼回事。請確保從函數中的任何代碼路徑return false,否則它將執行正常的表單提交(就像沒有JavaScript一樣)......就像你看到的一樣。由於沒有action屬性,因此它會提交到同一頁面。

所以這部分:

}); 
} else return false; 

應該是這樣,因此返回false不管:

}); 
} 
return false;