I have a table that looks like this:
When i click on the link it will make a pop up light box appear with information received from the ajax request. I use the id from the anchor tags data attribute to find relevant records.
My pop up box has left and right arrows, when clicked they should do another ajax request to repopulate the pop up box.
This is the first ajax request sent when a link is clicked:
$(document).ready(function(){
$('.modelLink').click(function(){
//getting the reviewID from the data attribute on the link clicked
var reviewID = $(this).data('id');
$.ajaxSetup({
headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
});
jQuery.ajax({
url:'/flyout/' + reviewID,
type: 'GET',
success: function( data ){
//setting the right buttons id for the next request
$('.fa-chevron-right').attr('data-id', data.nextID);
//this function has nothing to do with my problem.
fillFlyoutController(data);
},
error: function (xhr, b, c) {
console.log("xhr=" + xhr + " b=" + b + " c=" + c);
}
});
});
});
At this point my pop up box is great , showing all the relevant data. In the console the received data from the ajax request shows:
So you can see what i do in the first ajax request when i set the data-id for the right button to the 'data.nextID'.
Now when you click the right button it should fire of an ajax request around 97% the exact same code as seen below:
$(document).ready(function(){
$('.fa-chevron-right').click(function() {
//getting the reviewID from the right buttons data attribute
var reviewID = $(this).data('id');
$.ajaxSetup({
headers: {'X-CSRF-Token': $('meta[name=_token]').attr('content')}
});
jQuery.ajax({
url: '/flyout/' + reviewID,
type: 'GET',
success: function (data) {
//setting the right arrow reviewID to the nextID
$('.fa-chevron-right').attr('data-id', data.nextID);
//this function isn't relevant for this question.
fillFlyoutController(data);
},
error: function (xhr, b, c) {
console.log("xhr=" + xhr + " b=" + b + " c=" + c);
}
});
});
});
Now the strange thing is, this actually works the first time the right button is clicked. The returned json is as seen below When i console.log the data:
Okay, so theoretically every single time i click this right button now it should loop through the same process that just worked. However when i click it a second time, it brings back the same data.
By this i mean it actually goes through the ajax request , (even though the right button has a different id now) and returned the data from the previous request as seen below:
Any one have any ideas why this is not working?
EDIT:: by the way, i have also tried putting this second ajax request into a function and calling it from the right button onclick="".
Also i have tried replacing .click(); to bind("click", function) to try and bind button.
All of these thing i have tried result the same.
EDIT:: This is the html for right button
<i class="fa fa-chevron-right" data-id=""></i>