SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sending multiple Ajax requests

    Hi,
    I need to send 15 requests to my server and get results, these results are queries to other sites. I then update my page with the results. I need to know if I am taking the correct approach, as things are working a bit slow, and I.E. seems the be as slow as a snail. Here is my function for the first request

    Code:
    function one()
    {
      var xmlHttpa=null;
    try
      {
      xmlHttpa=new XMLHttpRequest();
    
    }
    catch (e)
      {
      try
        {
        xmlHttpa=new ActiveXObject("Msxml2.XMLHTTP");
    
    }
      catch (e)
        {
        try
          {
          xmlHttpa=new ActiveXObject("Microsoft.XMLHTTP");
    }
        catch (e)
          {
          alert("Your browser does not support AJAX!");
          return false;
          }
        }
      }
      
        xmlHttpa.onreadystatechange=function()
        {
        if(xmlHttpa.readyState==4)
          {
     	   document.getElementById('resulta').innerHTML = xmlHttpa.responseText;
    	  var el = document.getElementById('showMessagea');
          el.parentNode.removeChild(el);
    	   applystyle();
          }
        }
    
      xmlHttpa.open("GET","one.php",true);
      xmlHttpa.send(null);
      }
    i then call this function and others from my page, one(); two(); etc

    Am I correct in my approach?

  2. #2
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're making 15 Ajax requests, it's not surprising it's slow! If you want to speed it up, you'll have to reduce the number of requests. The fewer requests, the faster it will be.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •