I have a following HTML structure, which is a modal pop-up like following:
<!-- Left side of the pop up-->
<div class="pop-state">
<!-- state -->
<?php foreach ($users as $user) { ?>
<div class="pop-first-btn">
<a class="check-user" value="<?=$user['id']?>"><?=$user['username']?></a>
</div>
<?php } ?>
</div>
<!-- Right side of the modal popup-->
<div class="pop-brands" >
<?php for ($i = 0; $i < count($brandList); $i++) { ?>
<div class="pop-city-co" id="brands">
<label>
<input class="check-city" type="checkbox" name="" value="<?=$brandList[$i]['id']?>" data-id="<?=$i ?>"><?=$brandList[$i]['name']?>
</label>
</div>
<?php } ?>
</div>
And when a user clicks on the a link I do the following jQuery event:
$('.check-user').click(function() {
var user_id = $(this).attr('value');
$.post("/user/usersBrands", {userId:user_id}, function(data){
//console.log(data);
var brands = $('<div />').append(data).find('#brands').html();
$('#brands').html(brands);
console.log(brands);
});
});
I pick up the userId, send it to my function, and then I'd like to update the right side of my popup with the user list, in form of checkbox list... And this is my function that I'm calling:
public function usersBrandsAction(){
$userId = $this->getRequest()->getPost("userId");
if(!empty($userId))
{
$brandList = $this->getBrandModel()->brandList();
$this->dieCustomCode($brandList); // it can be echo instead of this or anything that would return me the array of brands...
}
}
So when I click on the a link, nothing shows up... the console says the #brands is undefined for some reason... Can someone help me out with this ? :/