I'm trying to send a AJAX request to a PHP file. The PHP file does not receive the request.
I'm using the following code:
register.php:
$('#button_step1').click(function(e) {
$.ajax({
type: 'POST',
url: '../core/views/cp/test.php',
data: { message: 'works' },
success: function(resp) {
alert(resp);
}
});
$('.step1 input').prop('disabled', true);
window.location.replace("http://10.0.0.13/core/views/cp/test.php");
});
test.php:
<?php
echo $_POST['message'];
?>
The message I get after I get redirected to test.php, "Notice: Undefined index: message in C:\xampp\htdocs\core\views\cp\test.php on line 3".
Issue 2:
When I require_once
my register_view.php
which includes the AJAX request into my register.php
and let it send a AJAX request to the register.php
file, it will show me the alert()
which has all data from the whole PHP file, where it should only show 'works'.
Code,
register.php:
<?php
require_once '../core/init.php';
$_SESSION['message'] = $_POST['message'];
echo $_SESSION['message'];
require_once VIEW_ROOT . '/cp/register_view.php';
register_view.php:
$('#button_step1').click(function(e) {
$.ajax({
type: 'POST',
url: '../core/views/cp/test.php',
data: { message: 'works' },
success: function(resp) {
alert(resp);
}
});
$('.step1 input').prop('disabled', true);
//window.location.replace("http://10.0.0.13/core/views/cp/test.php");
});