Páginas: [1]
  Imprimir  
Autor Tema: Peticiones GET y POST via JavaScript sin JQuery  (Leído 2080 veces)
0 Usuarios y 1 Visitante están viendo este tema.
WHK
吴阿卡
Administrador
Usuario constante
*****

Karma: +8/-3
Mensajes: 272


Coder

yan_unico_102
Ver Perfil WWW Email
« : Agosto 29, 2009, 03:08:57 »


Bueno, hace tiempo que hize este code para enviar y recibir datos atraves de JavaScript sin la utilización de JQuery.
Código:
function http_req(url, post_data){
 if(window.XMLHttpRequest){
  var ajaxResponse = new XMLHttpRequest();
 }else
  if(window.ActiveXObject){ // IE
   try{
    var ajaxResponse = new ActiveXObject("Msxml2.XMLHTTP");
   }catch(e){
    try {
     var ajaxResponse = new ActiveXObject("Microsoft.XMLHTTP");
    }catch(e){
	 return false;
	}
   };
  };
  if(!ajaxResponse){
   return false;
  };
  if(post_data){
   ajaxResponse.open('POST', url, false);
   ajaxResponse.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   ajaxResponse.send(post_data);
  }else{
   ajaxResponse.open('GET', url, false);
   ajaxResponse.send(null);
  }
  if(ajaxResponse.status == 200){
   return ajaxResponse.responseText;
  }else{
   return false;
  };
};
Y funciona así:
Código:
alert(http_req('http://translate.google.cl/translate_a/t?client=t&text=house&sl=en&tl=es', false);
Esta es una petición GET simple y para enviar post se hace así:
Código:
alert(http_req('http://localhost/test.ext?get_variable=get_valor', 'variable_post=valor_posr&otro=test');
« Última modificación: Agosto 29, 2009, 04:06:44 por WHK » En línea

3l3cTr0n1k_0
Programador
Usuario regular
*

Karma: +4/-1
Mensajes: 50


Ver Perfil WWW Email
« Respuesta #1 : Noviembre 14, 2009, 11:29:30 »


perdon man pero esto se llamaa ajax no javascript aunque ajax significa asincrono javascript y xml es una tecnologia deferente a ajavascript :D
En línea

nakp
Moderador global
Usuario regular
*****

Karma: +5/-1
Mensajes: 92



Ver Perfil
« Respuesta #2 : Noviembre 16, 2009, 09:25:34 »


wtf... diferente? xDDDD XMLHttpRequest y ActivXObject son objetos javascript disponibles dependiendo del navegador ajax = peticiones javascript y xml o json :P
En línea
3l3cTr0n1k_0
Programador
Usuario regular
*

Karma: +4/-1
Mensajes: 50


Ver Perfil WWW Email
« Respuesta #3 : Noviembre 18, 2009, 12:20:10 »


wtf... diferente? xDDDD XMLHttpRequest y ActivXObject son objetos javascript disponibles dependiendo del navegador ajax = peticiones javascript y xml o json :P
Claro y no lo discuto, pero son objeto asincronos que se pueden llamar cuando se requieras de eso nace el conceto "ajax"  ::)
En línea

Páginas: [1]
  Imprimir  
 
Ir a: