public function brandAjax($segment)
{
$brand=brands::where("segment_id",$segment)
->pluck('brands.brand_name,brands.brand_id')->all();
return json_encode($brand);
}
script
function getBrand(segment)
{
$(document).ready(function()
{
$(".test").click(function(){
var favorite = [];
$.each($("input[name='sg[{{$sg->segment_id}}]']:checked"), function(){
favorite.push($(this).val());
});
// alert("Selected Segment is: " + favorite.join(", "));
if(favorite.length>0)
{
$.ajax({ //create an ajax request to display.php
type: "POST",
url: '{{url('/')}}/brand/Ajax/'+segment,
data:{segment_id:favorite,action:1},
// dataType: "html", //expect html to be returned
success: function(response){
$("#brands").html(response);
// alert(response);
}
});
}
}
else
{
$("#brands").html("");
}
});
});
$(document).ready nested inside a function (it can work but it's bad design in my opinion). That being said, I would take it out of the function, put it above it and set the onchange event handler there.
I see. There is a lot of work to do and it's kinda hard to do it blindfolded (without testing). But I'll try and give you a heads up later today (gotta go back to bed if I don't want to fall asleep while working).