i need to fetch data from database from controller file and display into element file and ajax value showing in inspect element and also when i alert in ajax it is showing that value is going to controller.
but problem is that how can i echo or print ajax value in controller to fetch data from database and display it into element file?
how can i render custom element file in controller function?
ajax script
<script> $('#categories .accordion .tablist .tablistitem').on('click', function () { event.preventDefault(); $(".accordion li").removeClass("active"); var $li = $(this); $liid = $li.attr('id'); $slug = $li.data('slug'); $li.addClass("active"); $('#wrapper').append('<span id="load">LOADING...</span>'); $('#categories_info').show(); $.ajax({ type: 'POST', url: '/reviews/getsubcategories', data: {"selectid":$liid }, dataType:"text", success: function(data, textStatus, xhr) { alert(data); }, error: function(xhr, textStatus, error) { alert(textStatus); } }); }); </script> controller function
function getsubcategories() { echo $selectid= $_POST['selectid']; return $selectid; } element file
$SubCategoryObj = cri('Reviews'); $selectid = $SubCategoryObj->getMainCategories(); echo $selectid;