Ok got it, knew there must be some built-in WP solution to this. Simply call wp_get_referer()
in your callback (for details, see this).
At least it’s working as I need it, let me know if there’s any better solution.
UPDATE
Thanks to @Tom J Nowell, we should also mention that referrers could get stripped for privacy reasons or similar. To thus be on the safe side, there’s no way around passing the referrer’s URL explicitely to the data sent across AJAX, like using document.location.href
.
Related Posts:
- The correct method to pass query vars in AJAX using ajaxurl
- Dynamic URL to reference custom PHP files
- Concatenate site_url and string doesn’t work
- Removing all my hardcoded URLs with get_site_url()
- Filtered queries not responeding to page path
- How to get URL of current page displayed?
- Can I use the same nonce for multiple requests on the same page?
- How can I fetch loop of post titles via AJAX?
- Encode text string being appended as query to URL [closed]
- Adding “Remember Me” in custom login
- Is it safe to use $_SERVER[‘REQUEST_URI’]?
- Retrieve POST data from AJAX call
- username_exists() function can’t be access without logging in
- Using wp_send_json to return HTML
- WordPress AJAX Pagination with query_posts
- How build a custom login/register form with error handling?
- Is having multiple theme customizers for different pages possible?
- How to check if feed URL was requested?
- Do I require the use of nonce?
- What is the best practice for escaping data URIs?
- How to check if new posts have been published since page load?
- WordPress Ajax always returns a 404 error
- Where to include php files in wordpress and how to refer to them later [closed]
- urlencoding of the_title() doesn’t work?
- Redirect to Page after Post Submit
- How do I get the author’s page url from their ID?
- problem with ajax and the path to the php page
- Can i check if user is doing any ajax request?
- How to use wp_localize_script in a WordPress page other than functions.php?
- Admin Media grid view images won’t load
- Comparing arrays within a loop
- Real time Duplicate title check
- Ajax template: how to handle head section
- Passing JSON data from WP Query into AJAX causing NULL errors
- simple wordpress ajax plugin not working when not logged in
- Load custom field value into div with AJAX
- Security – Ajax and Nonce use [closed]
- AJAX / Read More: multiple check_ajax_referer() and wp_create_nonce() not working independentely
- Jquery ajax to custom php file: returning blank data
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- Accessing a random image via ajax
- PHP calling AJAX function that relies on passed PHP function values not working
- Update WordPress Custom Field with AJAX on cached page
- Looking for a better way to handle an ajax script that pulls in post data on click
- Targeting single page with JS
- Data fetch and delete by ajax request
- Handling an Ajax form submit
- Ajax call to my WordPress website from an external application [duplicate]
- Making a follow button, Ajax not talking to php
- How to add default images into theme customizer image control?
- Can’t use get_results() in ajax query
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Constructing a custom login form using ajax
- What’s the proper way to use wp_enqueue_script/style?
- Debugging PHP object during Ajax call in WordPress
- Validate a users email address when using gmail to register
- Callback URL in WordPress
- Custom WordPress+PHP+MYSQL+AJAX form, submit event not captured by Javascript, but does POST data to the DB
- WordPress Ajax Data problem
- Use ajax to update_post_meta
- Problem with WordPress Ajax form
- Click loads template via ajax
- Wrong links in WordPress?
- Newbie question: no index.php? in my plain wordpress permalink
- Display notification only once
- admin-ajax.php returning error 400 namespaced callback
- AJAX in WordPress, sending coords data to MySQL and show after into map
- How to retrieve the content (with a specific ID) via ajax by clicking a link tag
- WooCommerce: update custom fields after checkout validation failure
- Access/update database with jQuery
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- Passing jQuery value using Ajax to a page template
- How to set a custom path, for ajax image upload folder in admin?
- How is WordPress manipulating the posts like there are folders?
- admin-ajax.php responding with 0
- Ajax form submit within a Post Metabox
- ajax_object is not defined when ajax calls the function
- How to speed up admin-ajax.php in wordpress
- Returning a value from a PHP page
- Page Reloads Before AJAX Request Finishes
- WordPress File handle – fopen, fwrite not working with $.ajax or $.post Jquery
- Can I use HTTP POSTs? Is there a better alternative?
- Why is this Ajax not working?
- Stumped – Ajax Response Returns 0
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- How to make custom total price reactive in navigation
- Put CSS inside a PHP file and include it the right way
- Sending jsPDF documents to the server
- Ajax $wpdb not returning table data
- How to prevent those PHP variables from being cached on WordPress?
- Use ajax from function.php
- Extract subdomain and relative address from a url
- Remove query string specific key value
- Ajax return code 400
- How to Fetch values from WP database based on selected option value by onchange using PHP?
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- doing an ajax request always outputs 0
- Echo URL of large version of Featured Image
- Why does WordPress remove my variables in the URL?
- How to run JS, PHP and etc. inside WP post?