Bonjour à tous,
J'ai un problème à envoyer une requête AJAX avec IE (toutes versions confondues). Je veux vérifier un captcha en AJAX et s'il n'est pas bon, une alerte, un rafraîchissement du captcha et on n’envoie pas le formulaire. À tous les coups, après toutes les vérifications, le formulaire s'envoie même s'il n'y a rien dans le champ captcha. Ceci étant dit, avec FF et Opera tout fonctionne à merveille.
Voici mes bouts de code :
Code Javascript : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 function ajax(fichier, getdata, sync){ if(sync == null){sync=true;} if(window.XMLHttpRequest) // FIREFOX xhr_object = new XMLHttpRequest(); else if(window.ActiveXObject) // IE xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); else return(false); xhr_object.open("GET", fichier + '?nocache=' + Math.random() + "&" + getdata, sync); xhr_object.send(null); return xhr_object; } function verifierForm(formObj,lang){ if(trim(formObj.contactName.value) == ''){ alert(messageTexte['nom'+lang]); focusAndSelect(formObj.contactName); return false; } ajaxObj = ajax('include/ajax-check-captcha.php','captcha=' + formObj.contactCaptcha.value,false); alert('ici1'); if(ajaxObj.responseText != 'ok'){ alert('ici2'); alert(messageTexte['captcha'+lang]); refreshCaptcha(); focusAndSelect(formObj.contactCaptcha); return false; } sendMail(formObj,lang); return false; }
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 $output .= '<form name="contactForm" action="donothing.php" method="post" enctype="multipart/form-data" onsubmit="return verifierForm(this,\'fr\')"> <table> <tr><td style="text-align:right;">Votre nom : </td><td><input style="width:250px;" type="text" name="contactName" /></td></tr> <tr><td style="text-align:right;">Votre adresse courriel : </td><td><input style="width:250px;" type="text" name="contactEmail" /></td></tr> <tr><td style="text-align:right;">Le sujet de votre demande : </td><td><input style="width:250px;" type="text" name="contactSubject" /></td></tr> <tr><td style="text-align:right;vertical-align:top;">Votre message :</td><td><textarea style="width:250px;" name="contactMessage"></textarea></td></tr> <tr><td style="text-align:right;vertical-align:top;"><img src="captcha.php?nocache='.time().'" alt="Captcha" id="captcha" /></td><td style="vertical-align:top;"><input style="width:100px;" type="text" name="contactCaptcha" /> Rafraichir le code <a href="javascript:refreshCaptcha()"><img src="images/refresh.png" align="top" /></a></td></tr> <tr><td style="text-align:right;vertical-align:top;"> </td><td style="text-align:right;"><input style="width:150px;" type="submit" value="Envoyer" name="contactSubmit" /></td></tr> </table> </form>';
À noter que le alert('ici1') s'affiche mais pas le 2... Donc c'est là que ça coince. Le fichier donothing.php n'existe pas puisque la fonction sendMail envoie le courriel via AJAX.
C'est la première fois que j'ai ce genre de problème puisque j'ai déjà utilisé et j'utilise encore cette façon de faire.
Merci
TigerCX
Partager