Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/05/2011, 14:28
Minniek
 
Fecha de Ingreso: enero-2009
Mensajes: 178
Antigüedad: 15 años, 3 meses
Puntos: 2
http.responseText recibe un texto

Tengo una pagina con un boton que al hacer click en el link server me regresa usando ajax el resultado de la pagina index.jsp
Lo que deseo es sencillamente que en el index.jsp pueda realizar una funcion que dependiendo de algun valor retorne un valor o el otro como por ejemplo

if(valor==1)
// me devuelva "HOLA"
else
// me devuelva "COmo estas"

Pero solo me lo permite si coloco esto <%="cualquierCOsa"%>

Coloco el codigo que estoy utilizando, fijense en el index.jsp que es lo que quiero modificar GRACIAS

INDEX.JSP<html>
<head>
</head>
<body>
<%="Hola"%>
</body>
</html>


PRUEBA.JSP<html>
<head>
<script src="ajax.js"></script>
</head>
<body>
<a onClick="sendRequest('GET','index.jsp')" href="#">Server:</a>
<div id="ajax_res">blalba.</div>
</body>
</html>

AJAX.JSfunction createRequestObject(){
var req;
if(window.XMLHttpRequest){

req = new XMLHttpRequest();
}
else if(window.ActiveXObject){
//For IE 5+
req = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
}
return req;
}

//Make the XMLHttpRequest Object
var http = createRequestObject();

function sendRequest(method, url){
if(method == 'get' || method == 'GET'){
http.open(method,url);
http.onreadystatechange = handleResponse;
http.send(null);
}
}



function handleResponse(){
if(http.readyState == 4 && http.status == 200){
var response = http.responseText;
if(response){
alert(response);
document.getElementById("ajax_res").innerHTML = response;
}
}else{
document.getElementById("ajax_res").innerHTML = "<img src='images/loading.gif' width='32' height='32' />";
}
}