Moved json_encode to ajax call