Use la variable JS en la acción de formulario
<script> var url = foo(); </script>
<form method="POST" action=""+url enctype="multipart/form-data">
NachooCh
<script> var url = foo(); </script>
<form method="POST" action=""+url enctype="multipart/form-data">