Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Crea Objeto XMLHTTPRequest

function ajaxFunction()
{
var xmlhttp;
try
  { 
 	 // Firefox, Opera 8.0+, Safari 
      xmlhttp=new XMLHttpRequest(); 
  }
catch (e)
    { 	 // Internet Explorer  
     try
    {   
     xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
    }
    catch (e)
    	{
	 try
     	 {
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	 }
   	catch (e)
    	    {
	     alert("Explorador no soporta--------AJAX!");  
	     xmlhttp= false;  
	    }
       }	// fin si no es Internet Explorer
     }   // fin si no es Firefox
return xmlhttp;
} // fin de crear objeto XMLHTTPRequest

Ajax-creaObjeto-XMLHttpRequest

// description of your code here

Código JavaScript:
/*
*Esta libreria es una libreria AJAX creada por Javier Mellado con la inestimable
*colaboracion de Beatriz Gonzalez.
*y descargada del portal AJAX Hispano http://www.ajaxhispano.com
*contacto javiermellado@gmail.com
*
*Puede ser utilizada, pasada, modificada pero no olvides mantener
*el espiritu del software libre y respeta GNU-GPL
*/ 
function creaAjax(){
         var objetoAjax=false;
         try {
          /*Para navegadores distintos a internet explorer*/
          // jajajajaja ... IE tambien entra aqui ...
          objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
          try {
                   /*Para explorer*/
                   objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
                   }
                   catch (E) {
                   objetoAjax = false;
          }
         }

         if (!objetoAjax && typeof XMLHttpRequest!='undefined') {
          objetoAjax = new XMLHttpRequest();
         }
         return objetoAjax;
}
                                     


ajax_request? method to XHR detection

A oneline helper I put in all of my apps. Looks for HTTP headers that signal you're being called via an XmlHttpRequest. I use it for instant degradable AJAX by rendering a template if it's as usual but just rendering a partial if they just want that part!

  def ajax_request?
    request.env['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' || params[:ajax]  # params[:ajax] for safe-keeping, FIXME if it works w/ all browsers
  end

Increase the number of simultaneous XmlHttpRequests in Firefox

Firefox doesn't do a lot of simultaneous AJAX (or any kind of HTTP) requests. IE caps it at 2, too. This will allow you to test your XHR overload scripts, or just load pages faster in general.

1. Go to "about:config"
2. Find and edit the following
* network.http.pipelining=false
* network.http.pipelining.maxrequests=4
* network.http.proxy.pipeline=false
3. Make the false's true; I set my maxrequests at 20