Get page slug and assign a variable within functions.php

assuming you are properly adding the AJAX script to your theme via wp_enqueue_script, you can pass data to the script via wp_localize_script, which you should already be using to pass the path to admin-ajax.php if you are using AJAX correctly within your plugin or theme.

see the Codex page on AJAX for more info. this tutorial linked at the bottom of that page has all the examples you’ll need.

a purely javascript solution (which I don’t recommend) would be to use the location object to determine context.