Truth in advertising: this is a homework assignment that I'm struggling with.
I'm running XAMPP on my desktop. I'm using an AJAX post to send form data to a PHP page by way of the jQuery validation plug-in. Here's the JS:
var $infoForm = $('#infoForm');
$infoForm.validate({
submitHandler: function() {
var formValues = getFormValues();
$.post("/Week5/process.php", formValues, postResponse, "text");
}
});
function postResponse(response) {
$infoForm.fadeOut("slow", function() {
console.log(response);
$('#postResponse').empty().append('<p>' + (response.message ? response.message : 'The server is silent') + '</p>').slideDown("slow");
});
}
Here's process.php:
<?php
header("Content-type: application/json");
$message = array('message'=>'Thank you for your submission');
echo json_encode($message);
?>
This is what response
looks like in the console:
<br />
<b>Warning</b>: Unknown: failed to open stream: No such file or directory in <b>Unknown</b> on line <b>0</b><br />
<br />
<b>Fatal error</b>: Unknown: Failed opening required 'D:/User Data/johnr/OneDrive/Education/ICT 4510/htdocs/Week5/process.php' (include_path='C:\xampp\php\PEAR') in <b>Unknown</b> on line <b>0</b><br />
I get the same messages (without the HTML tags) in my Apache error logs. I don't think I have a path error, because when I change the URL in $.post()
from 'process.php' to something like 'foo.php' I get a 404 Not Found like I would expect to get. It seems like the server is finding process.php but then failing to find the response it renders. I don't think the validation plug-in is the problem, because I tried it by handling the form's submit event directly and the result didn't change:
$infoForm.submit(function(event) {
event.preventDefault();
var formValues = getFormValues();
$.post("/Week5/process.php", formValues, postResponse);
});
One last datapoint: I actually get two request/response events related to process.php. The first is a POST with the right request payload and the errors as the response payload. The second is a GET with no request or response payload.