I like the approach of extracting a function to handle the details of the ajax calls -- most students ended up duplicating code in that respect.