Created  deferred function to handle JSON response.