Fixing bug with ajax calls