Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
cabrinha98
10,616 Pointsajax Event on click?
Hey =)
I´m currently working on an php-script for friend-requests and I´m pretty far ... I justdont find out how I get my ajax-Event to run all the time on multiple divs =/
Background:
I´m generating div-container after my friendship-request was successful. In this div container I´m calling over ajax (for transmitting variables/array from my .js-File to my php-file) multiple data (profile_image and user_name). Every div-container has an unique id related to my mysql database.
Everything runs fine, except I´m only getting the data(profile_image and user_name) when clicking on the div ... I couldn`t figuring out another trigger ... so the data is displayed always inside the div as long as it is existing.
My JQuery:
$(".friendship").click(function() {
var data_string = $(this).attr("id");
$.ajax({
type: "POST",
url: 'friend_list.php',
data: { friend_data_string : data_string },
success: function(data)
{
document.getElementById(data_string).innerHTML = data;
}
});
My thought was to tell every existing div to have the state ('clicked') ... but haven`t found out anything in the web and searched for a couple of hours for a solution =/
Would be pretty thankful for helpful answers ... so my div`s are getting some life =)
mfg
2 Answers
Ryan Field
Courses Plus Student 21,242 PointsI'm not entirely sure what you're trying to do, but as far as I can tell, you want to retrieve information for all the divs once the first request is successful?
If that's the case, why not just perform another AJAX call in your success callback that collects all the IDs from the divs you want to populate and puts them into an array or object, and sends that to your PHP, which can turn around and give you back all the info you want at once?
cabrinha98
10,616 PointsHey ...
First of all the for your reply .. currently I've bound the Ajax on the jquerry click trigger and I want that the ajax directly collects all the Data and loads them into all my divs when the User enters the Page with all the successfully friendships.
So I'm looking for an alternative trigger for when the User enters the page that the Ajax collects all the ids.
Was yesterday just to deep into IT =) I think I will manage today to get it worin =)
Mfg