use REQUEST_URI instead HTTP_REFERER and check if request is not a ajax