Moved AJAX logic into Sammy function