I have added code for adding tab in app\code\Store\Nutrition\view\frontend\layout\catalog_product_view.xml
.
<page layout="2columns-left" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info.details">
<block class="Magento\Catalog\Block\Product\View" name="nutrition" as="nutrition" template="Store_Nutrition::product/view/nutrition.phtml" group="detailed_info" after="additional">
<arguments>
<argument translate="true" name="title" xsi:type="string">Nutrition Facts</argument>
</arguments>
</block>
</referenceBlock>
<move element="nutrition.tab" destination="product.info.details" after="additional"/>
</body>
</page>
On click of the tab an ajax request is sent which then fetches the data and displays in the tab. If the response is null the text is displayed as "No Data to display!"
Now if the response is null I do not want to display the tab.
I know I'll have to send the ajax request on some other event like page load or document ready so that I can get the response beforehand. However I don't know how to display or hide tab based on response.