i have a home page with some links that i want to let users to switch Categories from one to other (without page refresh).
i mean (loading content from PHP file that connects with database to get posts in the category that visitors want to get, based on the tags that will be clicked by visitors, also making the Clicked link active, by appending class=”active”)
so i want to use PHP, ajax and JSON if needed. but i don’t want to use jquery.
For a larger scale project, axios could be a good choice. However we do not know what level of project this is for, or the intentions behind the post; for the OP to learn as part of a personal website, or gather ready-made solutions for a corporate entity. Maybe I’m reading deeper between the lines than ahmad.ku intended; I’m interpreting “no jQuery” to mean “no libraries” in the broader sense – the basic Ajax demo works and is simple enough for anyone to pick apart if they so wish… maybe even learning a bit of something along the way, or prompting further research, or indeed, other useful suggestions from the community. You say “low level” code, I say “established” and “does the job”, afterall this is a bare-bones method that’s been out in the wild for years.
First of all to make ‘active’ on click on the links use the code. Here you will have to remove all the other ‘active’ class from the ‘a’ tag then only apply the ‘active’ class on the ‘anchor’ which is clicked. You can use the jQuery Each method to do this removal of class.
The code below shows how to do it.