this first time working ajax in new world lol.. been long time since have seen , has changed..
the problem having data ending in 1 div instead of accross page in 3 divs. if load divs manually comes out fine, when switch ajax in 1 div , data comma seperated well. think might have way handling array. have no experience in ajax working arrays way.
the comma seperated data ending in first div , dont need commas either.
here array (the first 2 elements combine in first div - name image)
array ( [0] => array ( [0] => testprofile [1] => http://www.example.com/dirname/dirname/dirname/images/no-avatar.png [2] => adad [3] => 02:32:08 ) )
here html divs
<td align="center" width="20%"><div id="userdata"></div></td> <td width="70%"><div id="mesdata"></div></td> <td align="center" width="10%"><div id="timedata"></div></td>
here ajax
function ajaxgetmessages(roomid, urlwithr) { $.ajax({ cache: false, datatype: 'json', method: 'get', url: urlwithr, data: { roomid: roomid, urlrnd: urlwithr, ajax: true }, success: function(data) { data.foreach(function(entry) { var alphaname = data[0]; var avatar = data[1]; var displayuser = alphaname+' <img src="'+avatar+'" alt="avatar" height="30" width="30" />'; document.getelementbyid("userdata").innerhtml = displayuser; document.getelementbyid("mesdata").innerhtml = data[2]; document.getelementbyid("timedata").innerhtml = data[3]; });//close foreach }//close success }); //close ajax }//close function
data
array of arrays. , you're looping on arrays foreach
. function(entry)
provides each sub-array function procedure assigning variable entry
, therefore access each item within sub-array using entry[0]
, entry[1]
, etc.
data.foreach(function(entry) { var alphaname = entry[0]; var avatar = entry[1]; var displayuser = alphaname+' <img src="'+avatar+'" alt="avatar" height="30" width="30" />'; document.getelementbyid("userdata").innerhtml = displayuser; document.getelementbyid("mesdata").innerhtml = entry[2]; document.getelementbyid("timedata").innerhtml = entry[3]; });//close foreach
Comments
Post a Comment