$.ajax({
type: "POST",
url: "bestilling.php",
data: {
width : $(window).width(),
height : $(window).height(),
screen_width : screen.width,
screen_height: screen.height
}
});
include (screen.php);
$screenhight = 'width';
$screenwidth = 'height';
$browserhight = 'screen_width';
$browserwidth = 'screen_height';
<?php
if( ! empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' // ajax forespørsel
) {
// sett inn i databasen
$window_height = $_POST['window_height'];
$window_width = $_POST['window_width'];
$screen_height = $_POST['screen_height'];
$screen_width = $_POST['screen_width'];
// sender kun dataene tilbake til $.ajax for å sjekke at alt virker
die(json_encode($_POST));
}
?><!DOCTYPE html>
<head>
<title>ajax testing</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$.ajax({
url : window.location.href,
type : 'POST',
data : {
window_height : window.outerHeight,
window_width : window.outerWidth,
screen_height : screen.height,
screen_width : screen.width
}
}).done(function(data) {
console.log(data); // dataene du postet ovenfor skal nå komme opp
// som JSON i konsollen din hvis alt virker
});
});
</script>
</head>
<body>
</body>
</html>