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.
Related Posts:
- which is the function that removes accented vowels?
- Slugs as breadcrumbs for Pages
- Sanitize slug title
- is_account_page() change to page slug
- Identical custom taxonomy slugs for same hierarchical children
- Use /prefix/postname as a slug in post_name?
- Get term slug by term id and then explode it
- How to assign php file(template) to several pages with same prefix page name/slug
- How Can I Create a Friendly Slug for a Dynamic Page?
- Display list of pages that contain a certain string within the slug
- Get child-pages slugs of current page into js-file
- remove empty paragraphs from the_content?
- wp_enqueue_script was called incorrectly
- Add multiple custom fields to the general settings page
- Set JPEG compression for specific custom image sizes
- Prevent “main” WPMU site_url() being returned in functions
- How to redirect to post if search results only returns one post
- bloginfo() vs get_option?
- Get recent posts with thumbnail
- Display Total Number of Social Shares
- how to create shortcode in wordpress
- Child theme – copied some files from parent to child website still uses parent files
- Function returns different value when called from ‘save_post’ than when called on page load
- Using locate-template & shortcodes doesn’t appear to work
- Widgets Section not displaying in theme customizer
- add sidebar area to header of child theme
- Displaying a random user with a shortcode
- Display a function using AJAX
- Hide the Private prefix on one specific page
- Updating users_can_register option?
- Custom registration URL lost when user makes signup mistake
- Images uploaded using media uploader are appearing upside down
- Empty Date Returned on my function
- Woocommerce Attributes pulling in wrong data
- How to get the post_name when in preview?
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- How to hook into a function offered by a plugin?
- Echo tags used to describe the theme
- Change position of media in admin menu
- How to Display Frontend CSS for Administrator only
- How can I change a function in a parent theme via a child themes functions.php
- How can I remove the main description text box in a Woocommerce product editor page? I only use the “Product short description” text box [closed]
- Automatically assign video ‘poster’ value to ‘filename’ for archive listing
- Unique sequential reservation code
- new_excerpt_more link not working properly
- Where to add the permalink in this function?
- Accessing two databases wordpress
- Add a jQuery Function
- Problem with comments_number()
- Functions when woocommerce isn’t installed
- How to get correct value from checked()?
- While loop with an exception after a count is reached
- Return child theme url
- Redefine function arguments before rendering
- Enqueue script on every page except one
- Best way to handle lack of titles in microblogging
- Functions php shortcode for displaying main menu with no child items
- Redirect to other page if login
- first paragraph of the_content as meta description
- get_terms (or tax_query) for term of current post?
- 404 when enqueue_script using plugin_url
- Do we need to change our child function.php to require/include child dir files when we add an over-riding file.php into the child theme
- How to use get_posts() function in functions.php
- Child theme functions.php
- How to echo Widget Title in Custom Frontend-Template Box
- Redirect to post after publish or update a published post
- Page Template Won’t Load Correct CSS File
- WordPress show bad the php hour and date
- How Can I add a menu to the theme from withen the function.php file
- show all the posts thumbnails
- the_excerpt function not showing image
- How to display this meta data (an array) in form of a function (created with a custom write panel)?
- WordPress – using sessions?
- Use a filter for wp_robots to block CPT/feed/
- Trigger email alert if file downloaded
- Completely Disable WordPress RSS Feeds
- How to hide content on mobile in the functions.php file – woocommerce
- Order column custom date using pre_get_posts
- query_vars treat as single var from URL
- Running javascript without hooking wp_head
- Remove text after a dot and a colon in Woocommerce product title
- Selecting specific query for offset
- Show image after X para – center aligned
- Restrict access if logged out except for homepage
- Add meta data in head from theme
- what is `get_section()` and how to use it?
- function replace_text for entire page
- Custom permalink rewrite rules – how do I fix this?
- How to echo the translated custom field?
- Only Show One Category Name Per Post
- Pass max posts to Javascript
- update_usermeta don’t work
- WP supersize not displaying when different languages flags are selected
- wp_list_pages change of children and anchor of parent
- How do I make my child theme’s CSS update when I save it?
- Bulk set Post Title as Tag where Tag is Empty Function
- Setcookie not setting cookies anywhere except admin
- WooCommerce, change “Add to Cart” to “Link to Product”, only for specific categories
- Remove or disable Appearance > Patterns
- Send An Email to Admin on User Profile Completion