move error and success handlers inside the ajax request