Hi I am trying to save some data, when a user reaches the order confirmation page, to a newly created table in the database and I am stuck. I know the AJAX call is communicating with the php file since I can simply console.log the response(output) and I get what is expected (Ie.: echo 'hello') from the php file - so all good here.
I also registered the new table alias inside the init.php.
Here is the JS code from the file order_message.tpl:
var newData = {
"one":"test one",
"two":"test two"
};
$.ajax({ url: '/newDir/newFile.php',
data: {
dataToSend: newData
},
type: 'post',
success: function(output){
console.log(output);
},
error: function(xhr, textStatus, error){
console.log(xhr.statusText);
console.log(textStatus);
console.log(error);
}
});
Here is the PHP code from the file root/newDir/newFile.php:
require '../init.php';
require '../include/func/func.db.php';
if(isset($_POST['dataToSend']) && !empty($_POST['dataToSend'])) {
$ssData = json_decode($_POST['dataToSend']);
myFunc($ssData);
} else {
die( header('Location: ../404.html') );
}
function myFunc($dt){
$toSaveData = array(
'one' => $dt->one,
'two' => $dt->two
);
func_array2insert ('my_new_table', $toSaveData);
}
I can see the AJAX call being made in the dev tools, but its outputting these errors:
- GET https://localhost/site/newDir/index.php 404 (Not Found)
- Not Found
- error
- Not Found
I did not reference anywhere in the code this path - which does not exist - https://localhost/site/newDir/index.php, so I'm not sure what is happening here. The next 3 errors are coming from the AJAX error method. And in the database no data is being stored.
If I comment out "require '../init.php';" I get no errors, but instead get a long string of html code. But still no data saved to the database.
Anyone can see what the issue may be?
Thanks a lot.