Fix several bugs on ajax. #3