converted code to ajax