Form submission in a widget on the dashboard

I have a very simple form inside one of my custom dashboard widgets. I can’t quite seem to get the submission to work properly and I haven’t been able to figure out why. Without using JavaScript, the form submission refreshes my page and causes me to log back into the panel every time. If I use JavaScript, I can do an e.preventDefault() and an $.ajax call to submit the form, but I can’t seem to get the url right for the form submission.

I tried a PHP script in a separate plugin file, but I’m not sure what to make the url for the AJAX call to reach that file from the dashboard. I also tried placing the PHP right in the same template as the widget, and just making the url for the AJAX call an empty string so that it would do a POST request to the same page, but that is causing the request to fail and return a 500 (Internal Server) Error.

Any thoughts on this?

UPDATE1: If I make the URL “site/plugins/widget/widget.php”, the AJAX does a request to
http://site.localhost/panel/site/plugins/widget/widget.php … Really I just need a way to access that same exact URL but without the “panel/” included.

UPDATE2: I tried making the url “…/site/plugins/widget/widget.php”, but this returns a 404 Error from a GET request (keep in mind my AJAX is making a POST request) at the url

Have you tried to get the file in the plugins folder with

<?php echo kirby()->roots()->plugins() . '...' ?>

Just tried this and got a 404 Error. This tries to access a file at
http://site.localhost/‘path-from-actual-root-to-php-file’, but that doesn’t work I think because I just need the extension from the site root, not my actual root.