JQuery method "POST"

Hi all,

Please help me to send the variable of JS to PHP $_POST.
I have the following code to get timezone of user:

$(document).ready(function() {
  var userTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
    $.ajax({
    type: "POST",
    data: {uTimezone: userTimezone}
  });
});

But I can’t to get this variable in php and don’t know which URL I need to put in a function because all URL are relative.

I dont believe you can pass a var from js to php, at least not directly. what I do is set a value in the html with the js and pass the var from the html to php in a form. to make it subtle, I will use hidden forms.

setting cookies would work, that might be a work around, but generally not recommended.

Why not? On the Internet a lot of examples of how to do this.
For example
Setting cookies I already did, but this is a bad solution for me.

the sample you linked is exactly what I told you to do(or maybe not, hell i don’t know, did i mention i hate jquery and it always confuses the crap out of me?). I can only explain what i know, and how i know how to do it, and i know it can give you your end result.

this one might explain better:

so for instance, use the js to set the value of the timezone using a hidden form, link the submit to say a button titled “set my timezone” with method post, then in the php get the post data, i.e. $_POST['user_timezone']

real world example:
a hidden form connected to a button:

js sets the value of said hidden form, from a select box on the page:

php grabs the data and handles the action: