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

Diferencia entre distintos ActiveXObject

Estas en el tema de Diferencia entre distintos ActiveXObject en el foro de Frameworks JS en Foros del Web. Hola, estoy empezando con AJAX, y me ha surgido esta duda a la hora de crear el objeto XMLHttpRequest. ¿Qué diferencia hay entre ActiveXObject("MSXML2.XMLHTTP") y ...
  #1 (permalink)  
Antiguo 05/07/2009, 08:40
Avatar de Legoltaz  
Fecha de Ingreso: agosto-2008
Mensajes: 325
Antigüedad: 15 años, 8 meses
Puntos: 6
Diferencia entre distintos ActiveXObject

Hola, estoy empezando con AJAX, y me ha surgido esta duda a la hora de crear el objeto XMLHttpRequest.

¿Qué diferencia hay entre ActiveXObject("MSXML2.XMLHTTP") y ActiveXObject("Microsoft.XMLHTTP")? ¿Cuándo se usa cada uno?

Uso esta función:

Código JavaScript:
Ver original
  1. function nuevoAjax(){
  2. var xmlhttp=false;
  3. try {
  4. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  5. } catch (e) {
  6. try {
  7. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  8. } catch (E) {
  9. xmlhttp = false;
  10. }
  11. }
  12.  
  13. if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  14. xmlhttp = new XMLHttpRequest();
  15. }
  16. return xmlhttp;
  17. }

Pero en un principio quise simplificarla de este modo, aunque sin tener en cuenta los distintos tipos de ActiveXObject y cuando se usan (he ahí me pregunta):

Código JavaScript:
Ver original
  1. function nuevoAjax(){
  2. var xmlhttp;
  3. if(document.all) xmlhttp = new ActiveXObject() //aquí tendría que hacer otro if para decidir cual de los dos ActiveXObject es el correcto, que es lo que no sé
  4. else xmlhttp = new XMLHttpRequest();
  5. return xmlhttp;
  6. }
  #2 (permalink)  
Antiguo 05/07/2009, 10:32
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Diferencia entre distintos ActiveXObject

Es para versiones antiguas del Internet Explorer. Aunque por lo general yo suelo usar sólo ActiveXObject("Microsoft.XMLHTTP")
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #3 (permalink)  
Antiguo 05/07/2009, 11:15
Avatar de Legoltaz  
Fecha de Ingreso: agosto-2008
Mensajes: 325
Antigüedad: 15 años, 8 meses
Puntos: 6
Respuesta: Diferencia entre distintos ActiveXObject

Gracias, David.
Entonces podría dejarlo así:

Código JavaScript:
Ver original
  1. function nuevoAjax(){
  2. var xmlhttp;
  3. try{
  4. xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
  5. }
  6. catch(e){
  7. try{
  8. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  9. }
  10. catch(er){
  11. try{
  12. xmlhttp = new XMLHttpRequest();
  13. }
  14. catch(err){
  15. xmlhttp = false;
  16. }
  17. }
  18. }
  19. return xmlhttp;
  20. }

Última edición por Legoltaz; 17/08/2009 a las 08:05
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 03:22.