Reputation: 365
I am developing a wordpress plugin and am having some trouble with the ajax side of things. What my plugin does is add a form and then validate the inputted data and store the values in a database.
My ajax post is as follows :
$.ajax({
type:"POST",
url: "process.php",
data: datastring,
success: function() {
$('#formwrapper').html("div id='message'></div>");
$('#message').html("<h2>Contact form submitted!</h2>")
.append("<p>We will be in touch soon.</p>").hide().fadeIn(1500, function() {
$('#message').append("<img id='checkmark' src='images/check.png' />");
});
}
});
The above code is in a javascript file in a folder called 'js' which is in the root directory of my plugin. The problem is when the data is submitted the ajax post cannot find "process.php". It is stored in the root directory of my plugin folder. I am wondering if there is not maybe a function I am missing which will allow me to find the url of the php file relative to the javascript file without having to set an absolute url path everytime ?
Upvotes: 0
Views: 3256
Reputation: 1207
When you want to access a file in a parent folder. You can use the ../ file to go up one directory. So to solve this, call:
../process.php
Upvotes: 0
Reputation: 74738
change this:
url: "process.php",
to this:
url: "../plugin/process.php",
As a side note you have missed a <
in the ajax success here:
$('#formwrapper').html("<div id='message'></div>");
//---------------------^-----------------------------here you missed '<'
Upvotes: 0
Reputation: 50
is your folder structure like this?
/
/js/file.js
/plugin/process.php
Because then you could just say
url: "../plugin/process.php",
or
url: "/plugin/process.php",
Upvotes: 0