I decided to stop using jQuery so I'm converting everything to pure JavaScript.
I have this ajax call and I want to send the last part of the url to the php server, but JSON.stringify() sends anempty object in the server.
Why is this happening?
AJAX call:
var ajax = new XMLHttpRequest();
ajax.open('get', 'ajax/autocomplete.php');
ajax.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
ajax.send(JSON.stringify({q: document.location.href.split('/').slice(-1)[0]}));
PHP:
<?php
require_once '../../private/core/init.php';
header('Content-Type: application/json');
print_r($_GET);//empty
$data = new AUTOCOMPLETE($_GET['q']);
echo json_encode($data->data());
?>
and I get this error: Undefined index: q
?q=......).