Made jQuery AJAX DRY script for registering messages to database.