Take a look at wp localize script. It’ll allow you to encode your url into a separate javascript object before your script is loaded. get_template_directory retrieves the absolute path to the directory of the current theme. Use it in case your WP install directory is different than your local development. The theme directory can also change if the folder is renamed or WP_CONTENT is in a different location.
<?php
// Register the script
wp_register_script( 'some_handle', 'path/to/myscript.js' );
// Localize the script with new data
$translation_array = array(
'send_form_php' => get_template_directory() . '/page-templates/template-parts/template-logic/send-form.php',
);
wp_localize_script( 'some_handle', 'object_name', $translation_array );
// Enqueued script with localized data.
wp_enqueue_script( 'some_handle' );
Then in your js file you can use:
<script>
// alerts 'Path to the send-form.php'
alert( object_name.send_form_php );
</script>
Related Posts:
- Custom WordPress+PHP+MYSQL+AJAX form, submit event not captured by Javascript, but does POST data to the DB
- Ajax form submit within a Post Metabox
- How to store data from multiple forms using ajax and php
- Ajax loaded form replaces form action with Ajax url
- prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
- Ajax call return 404
- Show success or error messages in Ajax response to WordPress custom registration form
- WordPress admin-ajax.php 400 bad request
- Ajax contact form return 0
- Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- How to change this ajax function to submit to the default wordpress content area instead of the custom field ‘seller notes’?
- Custom HTML form using PHP – help with ajax/username validation
- Submitting my form to the database and then redirecting to payment site
- Data inserted in database, but ajax calls error function
- ajax form function error
- How to correctly submit a search form and display the result in an independent page
- How build a custom login/register form with error handling?
- Metabox repeating fields – radio buttons not saving correctly
- Where to include php files in wordpress and how to refer to them later [closed]
- How to handle a custom form in wordpress to submit to another page?
- Admin Media grid view images won’t load
- Passing JSON data from WP Query into AJAX causing NULL errors
- Validate a users email address when using gmail to register
- Use ajax to update_post_meta
- Getting the dropdown menu to redirect to different pages?
- How do I test PHP files in WordPress?
- Can I use HTTP POSTs? Is there a better alternative?
- How to make custom total price reactive in navigation
- How do I let users upload files to a chosen location?
- How to test nonce with AJAX – Plugin development
- get current custom post ID by WP_Query method
- Creating a Multi-Level Associative Object Using AJAX
- Ajax category filtering products default show all
- Status 400 for AJAX POST Request with admin-ajax.php
- Modify HTML structure of fields in woocommerce checkout form
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Why ajax doesn’t work on certain wordpress hooks?
- Posting and image insertion problems after EasyApache4 and PHP 7 upgrade
- How to add a do_action on refreshing of WP customizer?
- Styling my own password protected page, how to deal with wrong password?
- Login to wordpress by clicking a link and specifying usernaname and password in url
- how to update and display an option without reloading the page
- WordPress hit memory limit but not from the server
- WordPress REST API register_rest_route give a 500 error
- After adding my website to a new server, I keep getting a unexpected end of file error, but the file is identitcal to it’s original source
- How can I find the cause of a 500 server error?
- admin-ajax GET response bad request
- Post not populating for custom post type based on category selection
- How to display success message correctly and delete it when the page is refreshed
- Using admin-post.php for admin form but it directs me to admin-post.php white screen
- SOAP Request/Parsing XML From wp_send_json_success
- Proper way to use WordPress function with AJAX PHP file
- form built dynamically with php, not submitting
- Search only working on front page (index) , not working on other pages
- Live search from database table
- How to make blog post entries appear as input form instead of just text?
- Page Options Saving But Not Updating In Backend
- How to split AJAX response into two divs
- How to set variables with AJAX request to use in another function in WordPress
- Search Ajax Call – Use Form Data in Response
- Why does PHP called with Jquery AJAX not allow additional php code to be added?
- Deleting records with AJAX, deleting records as I search
- Database entry removed on browser refresh, Ajax PHP jQuery
- HTML Form Question
- Updating user meta adds string count to value?
- I want to retrieve the email or username data entered for password reset, but failed. how can I do it?
- How to create a widget with a populated dropdown?
- ajax contact form not submit message
- Can’t make lazy load for my site, help!
- Change WooCommerce currency programmatically on AJAX request
- form submission reverts to index.php template
- use with class file into wp_ajax hook
- Javascript / PHP – closing the loop
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- Ajax call to php function doesn’t work PHP code
- Custom theme admin-ajax.php 400 (Bad Request)
- Ajax in a class instantiated via shortcode
- number of posts with “Load More”
- Creating wordpress user registration form
- How to send Ajax Call from frontend without using wp_localize_script in Theme
- Include search tags and users in my search results system
- Apply filters when loading post via ajax
- Passing link parameter values to form
- Processing forms with php to wordpress database
- ajax form with multiple submit buttons and values
- Modify php code to pass a page id as a parameter in order to create a breadcrumb
- How do I convince this button to do something when it is clicked?
- WordPress will suddenly stop saving files uploaded by my code (ran in nopriv ajax)
- Display default WordPress login/registration form into a modal window
- WP_Query based on another query on the page
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- Send foreach $_post method to contact form 7 [closed]
- Use HTML Form Data in PHP Function – WordPress Admin Page
- wp_enqueue_scripts with JS script as a string
- Contact form with dynamic dropdown and filter
- How to use url and amin-ajax.php
- WP – Ajax call back data printed in the console.log
- AJAX WP_Query’s order and orderby parameters not working
- How can I use AJAX in child theme template?