Pas de liens cliquables avec AJAX

Eléphant du PHP | 134 Messages

14 août 2006, 13:05

Bonjour,

Je viens de me mettre au JS en utilisant la methode AJAX.

j'ai commencer avec un petit script tout simple que j'ai copier sur un site avec des tutoriels. Celui-ci affiche un nom et une adresse email en fonction de l'ID que l'on tape dans un champ.

Un fois compris j'ai modifier le script pour que les infos s'inscrivent en HTML dans un DIV sous la forme d'un lien mailto: clasique.

Seulement au lieu d'afficher un lien cliquable, il m'affiche le code source HTML. Alors je voudrais savoir s'il existe une fonction particulière pour que le retour d'info du serveur soit interprété.

Voici mon code :

index.php

Code : Tout sélectionner

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Document sans titre</title> <script type="text/javascript"> function getHTTPObject() { var xmlhttp; /*@cc_on @if (@_jscript_version >= 5) try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } @else xmlhttp = false; @end @*/ if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } } return xmlhttp; } function majMail() { var rechRapide = document.getElementById("rapide").value; http.open("POST", url + escape(rechRapide), true); http.onreadystatechange = handleHttpResponse; http.send(null); } function handleHttpResponse() { if (http.readyState == 4) { results = http.responseText.split(","); //alert(results); var chaine = "<a href='mailto:" + results[0] + "' >" + results[1] + "</a>"; var retourchar = document.createTextNode(chaine); while (noeud=document.getElementById('momo').firstChild){ document.getElementById('momo').removeChild(noeud);} document.getElementById('momo').appendChild(retourchar); } } var url = "search.php?recherche="; var http = getHTTPObject(); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); </script> </head> <body> <form action="post"> Recherche rapide par ID: <input type="text" name="rapide" id="rapide" onkeyup="majMail();"/><br /> </form> <br /> <div name="momo" id="momo" style=" margin:auto; border:1px dotted #0099FF; background-color:#FFFFCC; height:200px; width:300px;"></div> </body> </html>

fichier search.php
if (isset($_POST['recherche'])){
$recherche=$_POST['recherche'];

mysql_connect("localhost", "root", "");
mysql_select_db("test");

$sql="SELECT `user_name`, `user_mail` FROM `users` WHERE `user_id` LIKE '".$recherche."'";



$res = mysql_query($sql);
$row = mysql_fetch_row($res); 

 if ($row) {

  echo "$row[0],$row[1]";
  }

mysql_close();
}

?>


dans mon DIV apparait non pas un lien cliquable mais ça :
<a href='mailto:[email protected]'>Devether</a>

ancillon
Invité n'ayant pas de compte PHPfrance

14 août 2006, 15:09

Code : Tout sélectionner

var ajx_toThis = ""; function affiche_html(ajx_nom_id,ajx_toThis) { // ajout d'un elément div id ajx_ajout_elements(ajx_nom_id); var ajx_ajout_id = "ajx_" + ajx_nom_id; ajx_toThis = ajx_toThis.replace(/<html>/,""); // try { if (document.getElementById) { document.getElementById(ajx_ajout_id).innerHTML = ajx_toThis; } else if (document.all) { document.all[ajx_ajout_id].innerHTML = ajx_toThis; } // } catch(e) { // } }
innerHTML affiche de l'html

Mais il ne faut du html trop sophistiqué car avec ie cela ne fonctionne pas.

Salutations.