Changing check.sql to support ajax