elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web (Moderador: #!drvy)
| | |-+  [AYUDA] javascript Variable = PHP echo
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [AYUDA] javascript Variable = PHP echo  (Leído 1,919 veces)
Miseryk

Desconectado Desconectado

Mensajes: 225


SI.NU.SA U.GU.DE (2NE1 - D-Unit)


Ver Perfil
[AYUDA] javascript Variable = PHP echo
« en: 1 Septiembre 2013, 22:11 pm »

Hola, mi problema es el siguiente, tengo un archivo HTML, que dentro tengo programación en javascript, y estoy queriendo hacer ésto:

Código
  1. <Script>
  2. var VARIABLE = Llamada a php PEPE.PHP;
  3.  
  4. alert(VARIABLE);
  5. </Script>
  6.  

PEPE.PHP
->
Código
  1. echo "1000";
  2.  

La llamada a php la hice con JQuery y Ajax, pero no funcionó, alguno tiene alguna idea?


En línea

Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It’s never too late to change our luck
So, don’t let them steal your light
Don’t let them break your stride
There is light on the other side
And you’ll see all the raindrops falling behind
Make it out tonight
it’s a revolution

CL!!!
EFEX


Desconectado Desconectado

Mensajes: 1.171


"Dinero Facil"


Ver Perfil WWW
Re: [AYUDA] javascript Variable = PHP echo
« Respuesta #1 en: 2 Septiembre 2013, 21:14 pm »

Ese es el codigo? esa no es la forma...

http://api.jquery.com/jQuery.ajax/


En línea

henkel

Desconectado Desconectado

Mensajes: 17


happy hacking


Ver Perfil
Re: [AYUDA] javascript Variable = PHP echo
« Respuesta #2 en: 3 Septiembre 2013, 05:34 am »

Este código es de http://www.w3schools.com/ajax/ajax_xmlhttprequest_create.asp
Código
  1. <!DOCTYPE html>
  2.  
Código
  1. function loadXMLDoc()
  2. {
  3. var xmlhttp;
  4. if (window.XMLHttpRequest)
  5.  {// code for IE7+, Firefox, Chrome, Opera, Safari
  6.  xmlhttp=new XMLHttpRequest();//la instancia al objeto de jquery
  7.  }
  8. else
  9.  {// code for IE6, IE5
  10.  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  11.  }
  12. xmlhttp.onreadystatechange=function()
  13.  {
  14.  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  15.    {
  16.    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
  17.    }
  18.  }
  19. xmlhttp.open("GET","ajax_info.txt",true);//get: tipo de envio http , "ajax_in..." nombre archivo, true indica que el envio es asincronico
  20. xmlhttp.send();
  21. }
  22.  

Código
  1. </head>
  2.  
  3. <div id="myDiv"><h2>Let AJAX change this text</h2></div>
  4. <button type="button" onclick="loadXMLDoc()">Change Content</button>
  5.  
  6. </body>
  7. </html>
  8.  
« Última modificación: 3 Septiembre 2013, 05:38 am por henkel » En línea

Henkel007
EFEX


Desconectado Desconectado

Mensajes: 1.171


"Dinero Facil"


Ver Perfil WWW
Re: [AYUDA] javascript Variable = PHP echo
« Respuesta #3 en: 3 Septiembre 2013, 20:48 pm »

Código
  1. function loadXMLDoc()
  2. {
  3. var xmlhttp;
  4. if (window.XMLHttpRequest)
  5.  {// code for IE7+, Firefox, Chrome, Opera, Safari
  6.  xmlhttp=new XMLHttpRequest();
  7.  }
  8. else
  9.  {// code for IE6, IE5
  10.  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  11.  }
  12. xmlhttp.onreadystatechange=function()
  13.  {
  14.  if (xmlhttp.readyState == 4 && (xmlhttp.status == 200 || xmlhttp.status == 0 && xmlhttp.responseText))
  15.    {
  16.    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
  17.    } else {
  18.        document.getElementById("myDiv").innerHTML = '<b>Error. HTTP ' + xmlhttp.status + '</b>'
  19.    }
  20.  }
  21. xmlhttp.open("GET","ajax_info.txt",true);
  22. xmlhttp.send();
  23. }
  24.  

Prueba este codigo, en firefox me funciono.
En línea

Miseryk

Desconectado Desconectado

Mensajes: 225


SI.NU.SA U.GU.DE (2NE1 - D-Unit)


Ver Perfil
Re: [AYUDA] javascript Variable = PHP echo
« Respuesta #4 en: 5 Septiembre 2013, 19:10 pm »

El problema no es la llamada, el código que encontré fue:

Código
  1. <Script>
  2. var VARIABLE;
  3.  
  4. jQuery.ajax(
  5. {
  6. type: 'post',
  7. url: 'PEPE.PHP',
  8. dataType: 'html',
  9. success:function(data)
  10. {
  11. VARIABLE = data;
  12. }
  13. });
  14.  
  15. alert(VARIABLE);
  16. </Script>
  17.  

Código
  1. PEPE.PHP
  2. echo "1000";
  3.  
En línea

Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It’s never too late to change our luck
So, don’t let them steal your light
Don’t let them break your stride
There is light on the other side
And you’ll see all the raindrops falling behind
Make it out tonight
it’s a revolution

CL!!!
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Duda con echo "<img .... y javascript
PHP
thecirujano 4 3,165 Último mensaje 31 Diciembre 2009, 13:07 pm
por thecirujano
Dos tipos de comillas en sentencia echo y funcion javascript
PHP
mokoMonster 2 3,097 Último mensaje 8 Diciembre 2011, 16:57 pm
por WHK
pasar variable javascript a php
PHP
soru13 1 2,998 Último mensaje 12 Abril 2012, 18:43 pm
por Shell Root
como meto un echo en una variable
PHP
General Dmitry Vergadoski 2 1,616 Último mensaje 13 Febrero 2014, 21:10 pm
por el_junior
[Resuelto] Ayuda while y echo en PHP
Desarrollo Web
KiddKeo 1 1,748 Último mensaje 19 Mayo 2018, 14:48 pm
por ivancea96
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines