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

Posts
1
Registration date
Thursday August 29, 2019
Status
Member
Last seen
August 29, 2019
- - Latest reply: ac3mark
Posts
13031
Registration date
Monday June 3, 2013
Status
Moderator
Last seen
October 11, 2019
- 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?
See more 

1 reply

Posts
13031
Registration date
Monday June 3, 2013
Status
Moderator
Last seen
October 11, 2019
1568
0
Thank you
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.
Respond to ac3mark