Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/04/2006, 19:42
Avatar de Wdeah
Wdeah
 
Fecha de Ingreso: julio-2005
Ubicación: Argentina
Mensajes: 109
Antigüedad: 18 años, 9 meses
Puntos: 0
Problemas con ajax

hola, ando teniendo unos inconvenientes con el temita.. es algo que no entiendo. voy a postear un codigo para que todos vean que esto funciona.

Código:
<script type="text/javascript">
var agt = navigator.userAgent.toLowerCase();
var is_op = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
var is_ie5 = (agt.indexOf("msie 5") != -1) && document.all && !is_op;

function CreateXmlHttpReq(handler) {
  var xmlhttp = null;
  if (is_ie) {
    var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
    try {
      xmlhttp = new ActiveXObject(control);
      xmlhttp.onreadystatechange = handler;
    } catch (ex) {
      alert("You need to enable active scripting and activeX controls");  
    }

  } else {
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onload = handler;
    xmlhttp.onerror = handler;
  }
  return xmlhttp;
}


function XmlHttpPOST(xmlhttp, url, data) {
  try {
    xmlhttp.open("POST", url, true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xmlhttp.send(data);

  } catch (ex) {
    // do nothing
  }
}


var myxmlhttp;
ratingMsgs = new Array(6);
ratingMsgColors = new Array(6);
barColors = new Array(6);

ratingMsgs[0] = "Demasiado corta";
ratingMsgs[1] = "Débil";
ratingMsgs[2] = "Justo";
ratingMsgs[3] = "Correcto";
ratingMsgs[4] = "Óptima";
ratingMsgs[5] = "Sin clasificar";

ratingMsgColors[0] = "#808080";
ratingMsgColors[1] = "#da5301";
ratingMsgColors[2] = "#ccbe00";
ratingMsgColors[3] = "#1e91ce";
ratingMsgColors[4] = "#1e91ce";
ratingMsgColors[5] = "#808080";

barColors[0] = "#e0e0e0";
barColors[1] = "#da5301";
barColors[2] = "#f0e54b";
barColors[3] = "#1e91ce";
barColors[4] = "#1e91ce";
barColors[5] = "#e0e0e0";

function CreateRatePasswdReq () {
var passwd = getElement('Passwd').value;
var email = getElement('Email').value;
var lastname = getElement('LastName').value;
var firstname = getElement('FirstName').value;
var min_passwd_len = 4;

if (passwd.length < min_passwd_len) {
	DrawBar(0);
}
else {
	passwd = escape(passwd);
	var params = 'Passwd='+passwd+'&Email='+email+'&FirstName='+firstname+'&LastName='+lastname;
	myxmlhttp = CreateXmlHttpReq(RatePasswdXmlHttpHandler);
	XmlHttpPOST(myxmlhttp, "https://www.google.com/accounts/RatePassword", params);
}
}

function getElement(name) {
if (document.all) {
	return document.all(name);
}
return document.getElementById(name);
}

function RatePasswdXmlHttpHandler() {
if (myxmlhttp.readyState != 4) {
 return;
}
rating = parseInt(myxmlhttp.responseText);
DrawBar(rating);
}

function DrawBar(rating) {
var posbar = getElement('posBar');
var negbar = getElement('negBar');
var passwdRating = getElement('passwdRating');
var barLength = getElement('passwdBarDiv').width;

if (rating >= 0 && rating <= 4) {
	posbar.style.width = barLength / 4 * rating;
	negbar.style.width = barLength / 4 * (4 - rating);
}
else {
	posbar.style.width = 0;
	negbar.style.width = barLength;
	rating = 5;
}
posbar.style.background = barColors[rating]
passwdRating.innerHTML = "<font color='" + ratingMsgColors[rating] +"'>" + ratingMsgs[rating] + "</font>";
}
</script>

<table width="100%"  border="0">
	<tr>
		<td width="30%">
<input type="hidden" value="" id="FirstName" size="30">
<input type="hidden" value="" id="LastName" size="30">
<input type="hidden" id="Email" value="" size="30">
<input type="password" id="Passwd" value="" onkeyup="CreateRatePasswdReq()" size="30">
</td>
<td width="70%">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="200" id="passwdBarDiv">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td nowrap valign="top"><font color="#808080" size="-1" face="Arial, sans-serif"><div id="passwdRating">Introducir</div></font></td>
</tr>
<tr>
<td height="3"></td>
</tr>
<tr>
<td colspan="2">
<table cellpadding="0" bgcolor="#ffffff" cellspacing="0" border="0" width="200">
<tr>
<td width="0%" id="posBar" bgcolor="#e0e0e0" height="4"></td>
<td width="100%" id="negBar" bgcolor="#e0e0e0" height="4"></td>
</tr>
</table>
</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
copien ese codigo y guardenlo en formato html, despues ejecutenlo y van a ver que funciona todo joya! sin problemas.
el tema es que cuando lo quiero implementar en mi web, me dice Acceso denegado.
es por el https del orto.. ya lo se, pero no entiendo porque aca funciona
pienso que es porque cuando ejecuto el archivo html, este no esta funcionando como pagina web, sino como un simple archivo, en cambio en mi localhost si..
gracias.