Close a modal window and refresh

Hi to everybody!
I have a question: i have a calendar app and when i click on a day i insert a new event. In this form, opened in a modal window, i need a button with a php script and after that i need to close the modal window and refresh the calendar. How can i do that? I tried to use on_exit but it doesn’t worlk because it works only in onClick and onScriptInit event.

Thanks and regards!