Improve javascript for ajax calls.