Reputation: 1260
I'm trying to read a php file from a js code in Wordpress.
$.ajax({
type: "POST",
url: "/set.php"
The problem is that the php file isn' t find in the directory, so at the end of js I have the alert of error.
How can I do to find the php file? Someone has a trick?
EDIT: i' ve just solved writing the full path as advised by your, but I' d like to write a "mini-path" without writing the full path. Some advised?
EDIT2: I' ve solved writing full path
Upvotes: 1
Views: 261
Reputation: 24579
When you use the path "/set.php" it looks for that file at the root directory. If it is one directory up from you JS file, then what you probably meant to do is "../set.php" instead. If you can describe your folder structure a little better we can help you out more.
[EDIT]
When the PHP file is in the same folder as the JS file, you can make the AJAX call like this:
$.ajax({
type: "POST",
url: "set.php"
Upvotes: 1
Reputation: 2259
As cillosis said, just use :
$.ajax({
type: "POST",
url: "set.php"
Upvotes: 2
Reputation: 457
url: "/set.php" means that file have to be in the root directory of your site. if it's located in your templates folder, then you have to write full path from root instead of one slash.
Upvotes: 1