To be completely proper, one should never directly include wp-load.php or any specific core file or files from their PHP code page. It should be the other way around, the WP environment includes your code page by the nature of a particular request. Attempting to do it the other way around in a plugin or theme submitted to the WP repository will get it kicked back to you unaccepted. The reason is the relative relationship between your code page and the specific core files can vary by installation.
Of course, if you’re not interested in the repository and are coding only for your own site, you can do whatever your like, but you should not expect that kind of advice here.
I somehow managed to omit the salient point of the method I was suggesting above. It wasn’t so much the javascript as that $path
pointed to a specific page based on a custom template. That template would be derived from whatever PHP code you are trying to execute. When requesting such a page, through whatever method, the WP environment is loaded for you as part of the page template loading process.
My apologies for completely omitting my primary point, you’re not the mind reader I thought your were ??