As question title, caching should be disabled either by:
appending unique javascript generated string in request:
/REST/data.php?u=32dajasda98s1641k801
sending Cache-control header:
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
every time you send dynamic content from the server to the client using ajax? When it's necessary and when it's not?
Basically you'll need to in one way or another disable caching every time you want to be guaranteed to get a "fresh" response from the server the next time you request data. If you don't, any proxy between you and the server or the server itself is allowed to cache the response and return it to you again on the next request.
This can be done straight in the script as in your examples or in (most? all?) web servers by configuring URLs that shouldn't be cached and the server will handle it for you.
The more "polite" of the two methods you mention is definitely the Cache Control Header which makes the proxies not cache at all. The dynamically generated one may still send headers allowing the proxy to cache, filling the cache up un-necessarily since only one request is made per URL.