<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="script.js"></script>
</head>
<body>
<div id="data">
Это блок с данными?
</div>
<span>Привет, как дела?</span>
</body>
</html>
function updateData(){
var xhr = new XMLHttpRequest();
xhr.open("GET", "server.php", true);
xhr.timeout = 10000;
xhr.ontimeout = function () {
console.error("The request for timed out.");
};
xhr.onload = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.response)
} else {
console.error(xhr.statusText);
}
}
updateData();
};
xhr.send('');
}
<?
$quantityCart = array("One" => 1, "Two" => 2, "Three" => 3);
$params = json_encode($quantityCart);
echo $params;
?>