specifying relative file paths in WP with jQuery requests not working

Why does it seem that WP requires me to utilize the entire and true file path instead of being able to use a relative file path? I know for safety its better not to use a true file path. In one of my functions, I am specifying a .php file located. Seems no matter what I do, I can not get my function to point to find the file.

The full directory that the php file is in domain_name/public_html/wp-content/mythemename/assets/php/select-change.php

A portion of the code that needs to locate my php file:

jQuery.post(assets/php/select-change.php); When using the above I get a 404 error and it tells me it can not find the file using - domain_name.com/page_name/php/select-change.php . It seems insistent upon putting the page name in there.

Even when I place the select-change.php file directly into the same directory that contains the calling .js file (assets/js), then it still cant find it since it is looking for mydomain_name.com/page_name/select-change.php which is not the path. Solution?

(ive also tried things like):

`jQuery.post(select-change.php);
jQuery.post(../select-change.php);
jQuery.post(/select-change.php);
jQuery.post(php/select-change.php);
jQuery.post(../../select-change.php);`

The PHP file:

function change_post() {
if($_POST  $_POST['change']){
$wpdb-get_results($wpdb-prepare('UPDATE Staff_Connector_Table SET Staff_List_Staff_Member_Id =  '.$_POST['change'].' Table_id ='.$tbl_id));
}
}

Topic paths jquery html Wordpress

Category Web


In PHP, it's not necessary to post to a PHP file, it is only required to include ( or require ) files and then use checks and validations to ensure that code is only processed when required.

You simply need to include the PHP file as part of your application - it will process the PHP is the conditions are met.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.