I made an Ajax request using JavaScript. I put the result in a variable called 'response'. I want to use the 'response' variable as a PHP variable "$response". How can I do it?
<html>
<head>
<script src="{{asset("jquery/jquery.js")}}"></script>
</head>
<body>
<h1>AJAX</h1>
<div id="id01"> {{$response}}</div>
<script type="text/javascript">
var req = new XMLHttpRequest();
req.open("GET","{{route('allcontacts')}}",true);
req.onload = function() {
if (req.readyState == 4 && req.status == 200) {
response = JSON.parse(req.responseText);
$("id01").html(response);
}
};
req.send();
</script>
</body>
</html>