Passing JavaScript Variable to PHP Session variable

前端 未结 5 470
梦谈多话
梦谈多话 2021-01-24 00:47

I am trying to update/create session variable when I change the option thru a drop-down box. TThe value is stored in a javascript function. Can any1 tell me how I can pass this

5条回答
  •  生来不讨喜
    2021-01-24 01:09

    No ajax? ok,

    var img = new Image();
    img.src = "script.php?myVal=" + encodeURIComponent(theValueToPass);
    

    The browser will try to load the image by requesting the url. Obviously it will be a fools errand, but your php script will get executed and the value available in php's $_GET['myVal']

提交回复
热议问题