I am trying to load some content via ajax into a div that has been previously loaded using another ajax function and I am having a really hard time putting the data into the div. Either, they are all loaded with the same content or nothing at all. I am sure it is something really simple that I am missing - any help will be greatly appreciated.
Ajax function:
$(document).on('click', '.btn.btn-clearview.loadSubresults', function () {
$.ajax({
type: "POST",
url: "loadData.php",
data: $(this.form).serialize(), // serializes the form's elements.
dataType: 'json',
success: function(data)
{
console.log(data);
$(this).closest('.wrapper').children('.resultExpander').html(data); // Should be doing something but nothing is happening (OPTION 1)
//$('.resultExpander').html(data); // Load the response from the PHP into the HTML (OPTION 2)
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
How this all pulls together:
User loads the main results page --> clicks the search button and loads the results via ajax. This result has a div with class "result" and there are multiple instances of this div.
From what I understand, using the traversing rules (https://learn.jquery.com/using-jquery-core/traversing/) I can target the required div even though the same class name is used throughout.
Error messages / information from the console on Firefox
none -- just does not load if I use option 1
Thanks.