Holders AZ Alkmaar and 18-time winners Ajax survived extra-time scares to reach the third round of the KNVB Beker.