Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,
I am unable to display data in the set of divs from mysql database.
The data is showing only in last div,below is my code:

$(document).ready(function (){
var n = 9;

for(var i=0;i<n;i++){
    var div = document.createElement('div');
	
    div.className = "d5";
	div.id=i+1;
   
	
    document.getElementById('container').appendChild(div);
	
    $.ajax({                                      
      url: 'myapi.php',                  //the script to call to get data          
      data: "",                        //you can insert url argumnets here to pass to api.php for example "id=5&parent=6"
      dataType: 'json',                //data format      
      success: function(data)          //on recieve of reply
      {
        var Name = data[2];              //get id
        //var vname = data[1];           //get name
        
        $('#'+div.id).html(""+Name);     
        
      } 
    });
  
   
}
	});


please help me to get the solution.
Posted
Comments
ZurdoDev 5-Feb-15 7:51am    
You'll need to debug it and see what is happening.
[no name] 5-Feb-15 7:53am    
how to debug it?

The data is shown in the last div.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900