Page 1 of 1

assign val to div using Ajax , calling ajax in loop

Posted: Sat Jan 24, 2009 8:14 am
by uday M
~pickle: Please use

Code: Select all

 tags where appropriate so code is easier to read.[/b][/color]

hi,
I am calling Ajax in javascript loop and assign response value to div .if I alert message (lastrssbridgeurl) it is work fine but after removing alert it fill only last div.

my Javascript code :-
[syntax=javascript]  for (var i in interest_array )
   {
       makeGetRequest(interest_array[i]);
       loopDelay(1000);// for delay in loop
  }[/syntax]

Ajax code:
[syntax=javascript]function createRequestObject() {
        var tmpXmlHttpObject;
 
        //depending on what the browser supports, use the right way to create the XMLHttpRequest object
        if (window.XMLHttpRequest) {
        // Mozilla, Safari would use this method ...
        tmpXmlHttpObject = new XMLHttpRequest();
 
        } else if (window.ActiveXObject) {
        // IE would use this method ...
        tmpXmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
        }
 
        return tmpXmlHttpObject;
  }
 
  //call the above function to create the XMLHttpRequest object
  var http = createRequestObject();
 
 
  function makeGetRequest(interest_Id) {
 
        //make a connection to the server ... specifying that you intend to make a GET request
        //to the server. Specifiy the page name and the URL parameters to send
 
       var lastrssbridgeurl="http://localhost/TheInterest.com/index.php/news/get_news/"+interest_Id;
//        alert(lastrssbridgeurl);
 
        http.open('get', lastrssbridgeurl,true);
       //assign a handler for the response
        http.onreadystatechange =function(){ processResponse(interest_Id)}
 
        //actually send the request to the server
        http.send(null);
  }
 
  function processResponse(interest_Id) {
        //check if the response has been received from the server
        var div_name="detail_"+ interest_Id;
 
        if(http.readyState == 4){
 
        //read and assign the response from the server
        var response = http.responseText;
        //do additional parsing of the response, if needed
 
        //in this case simply assign the response to the contents of the <div> on the page.
          document.getElementById(div_name).innerHTML =response;
        }
   }[/syntax]
[color=#FF0000][b]~pickle: Please use [code=...] tags where appropriate so code is easier to read.[/b][/color]