The script works only through ajax