I knew it before i even looked at your code when i saw this...
"Hurray it shows the result correctly as it should but only a split second before the whole page redirects to modules.php"
This toled me your AJAX is working, it's something more basic causing the issue.
Glad it's working =)