How to loop year & month condition together to filter correctly via AJAX?

How to loop year & month condition together to filter correctly via AJAX?