Foros del Web » Programando para Internet » Javascript » Frameworks JS »

problema al rescatar mas de una variable

Estas en el tema de problema al rescatar mas de una variable en el foro de Frameworks JS en Foros del Web. @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código ajax: Ver original <script language="javascript" type="text/javascript"> function handleHttpResponse() {     if (http.readyState == 4) {        if (http.status == ...
  #1 (permalink)  
Antiguo 27/07/2009, 11:39
Avatar de mc_quake  
Fecha de Ingreso: enero-2006
Ubicación: www.ecocargo.cl
Mensajes: 683
Antigüedad: 18 años, 3 meses
Puntos: 8
problema al rescatar mas de una variable

Código ajax:
Ver original
  1. <script language="javascript" type="text/javascript">
  2. function handleHttpResponse() {
  3.     if (http.readyState == 4) {
  4.        if (http.status == 200) {
  5.           if (http.responseText.indexOf('invalid') == -1) {
  6.              // Armamos un array, usando la coma para separar elementos
  7.              results = http.responseText.split(",");
  8.              document.getElementById("campoMensaje").innerHTML = results[0];     
  9.              enProceso = false;
  10.           }
  11.        }
  12.     }
  13. }
  14.  
  15. function AJAXpr_tipo() {
  16.     if (!enProceso && http) {
  17.        var valor = escape(document.getElementById("pr_tipo").value);
  18.        var url = "../ajax/valida_pro.asp?pr_tipo="+ valor;
  19.        http.open("GET", url, true);
  20.        http.onreadystatechange = handleHttpResponse;
  21.        enProceso = true;
  22.        http.send(null);
  23.     }
  24. }
  25.  
  26.  
  27. function handleHttpResponse1() {
  28.     if (http.readyState == 4) {
  29.        if (http.status == 200) {
  30.           if (http.responseText.indexOf('invalid') == -1) {
  31.              // Armamos un array, usando la coma para separar elementos
  32.              results1 = http.responseText.split(",");
  33.              document.getElementById("campoMensaje1").innerHTML = results1[0];   
  34.              enProceso = false;
  35.           }
  36.        }
  37.     }
  38. }
  39.  
  40. function AJAXpr_precio() {
  41.     if (!enProceso && http) {
  42.        var valor = escape(document.getElementById("pr_precioprovee").value);
  43.        var url = "../ajax/valida_pro.asp?pr_precio="+ valor;
  44.        http.open("GET", url, true);
  45.        http.onreadystatechange = handleHttpResponse1;
  46.        enProceso = true;
  47.        http.send(null);
  48.     }
  49. }
  50.  
  51. function getHTTPObject() {
  52.     var xmlhttp;
  53.     /*@cc_on
  54.     @if (@_jscript_version >= 5)
  55.        try {
  56.           xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  57.        } catch (e) {
  58.           try {
  59.              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  60.           } catch (E) { xmlhttp = false; }
  61.        }
  62.     @else
  63.     xmlhttp = false;
  64.     @end @*/
  65.     if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  66.        try {
  67.           xmlhttp = new XMLHttpRequest();
  68.        } catch (e) { xmlhttp = false; }
  69.     }
  70.     return xmlhttp;
  71. }
  72.  
  73. var enProceso = false; // lo usamos para ver si hay un proceso activo
  74. var http = getHTTPObject(); // Creamos el objeto XMLHttpRequest
  75.  
  76. </script>

i los valores los muestro en los siguientes div

<div id="campoMensaje"></div>
<div id="campoMensaje1"></div>

lo que sucede es que el div <div id="campoMensaje1"></div> me muestra que esta no definido

y el div <div id="campoMensaje"></div> si me muestra bien el mensaje

como puedo usar para hacer varias funciones mas y poder mostrar mensajes en donde yo quiera con distintos div

otra cosa alguien save como puedo devolver un valor con ajax???
__________________
Mc_Quake

Para ayudar en lo que se pueda:Zzz:
  #2 (permalink)  
Antiguo 27/07/2009, 12:43
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: problema al rescatar mas de una variable

Hola

Con esta función puedes llenar los dos div. Supongamos que te trae "coche,camión", haces el split, le pones el subindice y puede colocar cada elemento en un campo distinto

Código javascript:
Ver original
  1. function handleHttpResponse() {
  2.  
  3.     if (http.readyState == 4) {
  4.  
  5.        if (http.status == 200) {
  6.  
  7.           if (http.responseText.indexOf('invalid') == -1) {
  8.  
  9.              // Armamos un array, usando la coma para separar elementos
  10.  
  11.              results = http.responseText.split(",");
  12.  
  13.              document.getElementById("campoMensaje").innerHTML = results[0];    
  14.              document.getElementById("campoMensaje1").innerHTML = results[1];    
  15.  
  16.              enProceso = false;
  17.  
  18.           }
  19.  
  20.        }
  21.  
  22.     }
  23.  
  24. }

¿Te refieres a eso?

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #3 (permalink)  
Antiguo 27/07/2009, 13:16
Avatar de mc_quake  
Fecha de Ingreso: enero-2006
Ubicación: www.ecocargo.cl
Mensajes: 683
Antigüedad: 18 años, 3 meses
Puntos: 8
Respuesta: problema al rescatar mas de una variable

Cita:
Iniciado por Adler Ver Mensaje
Hola

Con esta función puedes llenar los dos div. Supongamos que te trae "coche,camión", haces el split, le pones el subindice y puede colocar cada elemento en un campo distinto

Código javascript:
Ver original
  1. function handleHttpResponse() {
  2.  
  3.     if (http.readyState == 4) {
  4.  
  5.        if (http.status == 200) {
  6.  
  7.           if (http.responseText.indexOf('invalid') == -1) {
  8.  
  9.              // Armamos un array, usando la coma para separar elementos
  10.  
  11.              results = http.responseText.split(",");
  12.  
  13.              document.getElementById("campoMensaje").innerHTML = results[0];    
  14.              document.getElementById("campoMensaje1").innerHTML = results[1];    
  15.  
  16.              enProceso = false;
  17.  
  18.           }
  19.  
  20.        }
  21.  
  22.     }
  23.  
  24. }

¿Te refieres a eso?

Suerte
si probe con eso pero no me funciona
lo tengo asi

Código ajax:
Ver original
  1. <script language="javascript" type="text/javascript">
  2. function handleHttpResponse() {
  3.     if (http.readyState == 4) {
  4.        if (http.status == 200) {
  5.           if (http.responseText.indexOf('invalid') == -1) {
  6.              // Armamos un array, usando la coma para separar elementos
  7.              results = http.responseText.split(",");
  8.              document.getElementById("campoMensaje").innerHTML = results[0];
  9.              document.getElementById("campoMensaje1").innerHTML = results[1];
  10.              enProceso = false;
  11.           }
  12.        }
  13.     }
  14. }
  15.  
  16. function AJAXpr_tipo() {
  17.     if (!enProceso && http) {
  18.        var valor = escape(document.getElementById("pr_tipo").value);
  19.        var url = "../ajax/valida_pro.asp?pr_tipo="+ valor;
  20.        http.open("GET", url, true);
  21.        http.onreadystatechange = handleHttpResponse;
  22.        enProceso = true;
  23.        http.send(null);
  24.     }
  25. }
  26.  
  27.  
  28. function AJAXpr_precio() {
  29.     if (!enProceso && http) {
  30.        var valor = escape(document.getElementById("pr_precioprovee").value);
  31.        var url = "../ajax/valida_pro.asp?pr_precio="+ valor;
  32.        http.open("GET", url, true);
  33.        http.onreadystatechange = handleHttpResponse;
  34.        enProceso = true;
  35.        http.send(null);
  36.     }
  37. }
  38.  
  39. function getHTTPObject() {
  40.     var xmlhttp;
  41.     /*@cc_on
  42.     @if (@_jscript_version >= 5)
  43.        try {
  44.           xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  45.        } catch (e) {
  46.           try {
  47.              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  48.           } catch (E) { xmlhttp = false; }
  49.        }
  50.     @else
  51.     xmlhttp = false;
  52.     @end @*/
  53.     if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  54.        try {
  55.           xmlhttp = new XMLHttpRequest();
  56.        } catch (e) { xmlhttp = false; }
  57.     }
  58.     return xmlhttp;
  59. }
  60.  
  61. var enProceso = false; // lo usamos para ver si hay un proceso activo
  62. var http = getHTTPObject(); // Creamos el objeto XMLHttpRequest
  63.  
  64. </script>


y el valida pro es

Código asp:
Ver original
  1. <%
  2. pr_tipo = int(Request.QueryString("pr_tipo"))
  3. pr_precio = Trim(Request.QueryString("pr_precio"))
  4.  
  5. If Int(pr_tipo) = 0 and pr_precio = "" Then
  6.  
  7.   response.write "<img src=""../_imag/tinto.jpg"" width=""10"" height=""10"" />"
  8.  
  9. ElseIf Int(pr_tipo) = 1 and pr_precio = "" Then
  10.  
  11.   response.write "<img src=""../_imag/blanco.jpg"" width=""10"" height=""10"" />"
  12. End If
  13.  
  14.  
  15. if pr_precio <> "" Then
  16.  
  17. sHTML = sHTML & "<table border=""0"" cellpadding=""2"" cellspacing=""0"">"
  18. sHTML = sHTML & "  <tr>"
  19. sHTML = sHTML & "    <td width=""95""><h3>Precio V.Oferta</h3></td>"
  20. sHTML = sHTML & "    <td>&nbsp;</td>"
  21. sHTML = sHTML & "  </tr>"
  22. sHTML = sHTML & "  <tr>"
  23. sHTML = sHTML & "    <td><h3>Precio Mercado</h3></td>"
  24. sHTML = sHTML & "    <td>&nbsp;</td>"
  25. sHTML = sHTML & "  </tr>"
  26. sHTML = sHTML & "</table>"
  27.  
  28.  
  29.  
  30. response.write(sHTML)
  31.  
  32. End If

en el div campoMensaje me funciona bien
pero cuando hago click en el campo de texto en el cual llamo con el evento onclik a la funcion AJAXpr_precio() me muestra el texto en el div campoMensaje y no en el div campoMensaje1
__________________
Mc_Quake

Para ayudar en lo que se pueda:Zzz:
  #4 (permalink)  
Antiguo 28/07/2009, 12:44
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: problema al rescatar mas de una variable

Hola

Prueba de esta manera

Código javascript:
Ver original
  1. <script language="javascript" type="text/javascript">
  2.  
  3. function handleHttpResponse() {
  4.  
  5.     if (http.readyState == 4) {
  6.  
  7.        if (http.status == 200) {
  8.  
  9.           if (http.responseText.indexOf('invalid') == -1) {
  10.  
  11.              // Armamos un array, usando la coma para separar elementos
  12.  
  13.              results = http.responseText.split(",");
  14.  
  15.              document.getElementById("campoMensaje").innerHTML = results[0];
  16.  
  17.              document.getElementById("campoMensaje1").innerHTML = results[1];
  18.  
  19.              enProceso = false;
  20.  
  21.           }
  22.  
  23.        }
  24.  
  25.     }
  26.  
  27. }
  28.  
  29.  
  30. function AJAXpr_tipo() {
  31.  
  32.     if (!enProceso && http) {
  33.  
  34.        var valortipo = escape(document.getElementById("pr_tipo").value);
  35.        var valor = escape(document.getElementById("pr_precioprovee").value);
  36.  
  37.        var url = "../ajax/valida_pro.asp?pr_tipo="+ valortipo + "&pr_precio=" + valorprecio;
  38.  
  39.        http.open("GET", url, true);
  40.  
  41.        http.onreadystatechange = handleHttpResponse;
  42.  
  43.        enProceso = true;
  44.  
  45.        http.send(null);
  46.  
  47.     }
  48.  
  49. }
  50.  
  51.  
  52. function getHTTPObject() {
  53.  
  54.     var xmlhttp;
  55.  
  56.     /*@cc_on
  57.  
  58.     @if (@_jscript_version >= 5)
  59.  
  60.        try {
  61.  
  62.           xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  63.  
  64.        } catch (e) {
  65.  
  66.           try {
  67.  
  68.              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  69.  
  70.           } catch (E) { xmlhttp = false; }
  71.  
  72.        }
  73.  
  74.     @else
  75.  
  76.     xmlhttp = false;
  77.  
  78.     @end @*/
  79.  
  80.     if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  81.  
  82.        try {
  83.  
  84.           xmlhttp = new XMLHttpRequest();
  85.  
  86.        } catch (e) { xmlhttp = false; }
  87.  
  88.     }
  89.  
  90.     return xmlhttp;
  91.  
  92. }
  93.  
  94.  
  95. var enProceso = false; // lo usamos para ver si hay un proceso activo
  96.  
  97. var http = getHTTPObject(); // Creamos el objeto XMLHttpRequest
  98.  
  99.  
  100. </script>


Código asp:
Ver original
  1. pr_tipo = int(Request.QueryString("pr_tipo"))
  2. pr_precio = Trim(Request.QueryString("pr_precio"))
  3.  
  4. If Int(pr_tipo) = 0 and pr_precio = "" Then
  5.  
  6. sHTML = "<img src=""../_imag/tinto.jpg"" width=""10"" height=""10"" />,"
  7.  
  8. ElseIf Int(pr_tipo) = 1 and pr_precio = "" Then
  9.  
  10. sHTML = "<img src=""../_imag/blanco.jpg"" width=""10"" height=""10"" />,"
  11. End If
  12.  
  13.  
  14. if pr_precio <> "" Then
  15.  
  16. sHTML = sHTML & "<table border=""0"" cellpadding=""2"" cellspacing=""0"">"
  17. sHTML = sHTML & "  <tr>"
  18. sHTML = sHTML & "    <td width=""95""><h3>Precio V.Oferta</h3></td>"
  19. sHTML = sHTML & "    <td>&nbsp;</td>"
  20. sHTML = sHTML & "  </tr>"
  21. sHTML = sHTML & "  <tr>"
  22. sHTML = sHTML & "    <td><h3>Precio Mercado</h3></td>"
  23. sHTML = sHTML & "    <td>&nbsp;</td>"
  24. sHTML = sHTML & "  </tr>"
  25. sHTML = sHTML & "</table>"
  26.  
  27. response.write(sHTML)
  28.  
  29. End If

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:27.