AJAX - Post client side screen width to server side php file

Closed
BRANDADAM Posts 1 Registration date Thursday August 29, 2019 Status Member Last seen August 29, 2019 - Aug 29, 2019 at 01:27 PM
 Blocked Profile - Aug 29, 2019 at 01:58 PM
Hello,



I have done this and it works fine but it's not really efficient picking up the screen width when the orientation of the device has changed (IT DOES) but is a bit slow but works perfectly

$(document).ready(function() {
var width;
width = $(window).width();
var screenWidth = width;
$.ajax({
method: "POST",
url: "menu.php",
data: {
screenWidth : width
},
success: function (res) {
$('body').html(res);
}
});
});
I'm aware of orientationchange function but not quite sure how to piece it together with say for example device that don't have an orientation change such as desktop/ laptop devices

Does anyone have a better/ more efficient way of doing this (posting the client's screen width to a server-side PHP script) including for orientation change?
Related:

1 response

Blocked Profile
Aug 29, 2019 at 01:58 PM
Query the client to find what type of browser the client is using, or theOS itself.

Use $user_agent

Desktop versions can be trapped and therefore do not need to scrubbed for orientation.
0