Fixes some bugs in ajax function
Adds the possibility to execute commands when ajax success