Imagine I have a script abc.js, which has one global variable userid. Several AJAX requests are made instantly after it is loaded (it can happen after or before DOM is parsed by browser). I need the script to have different variable value for different users. Requests has to be made instantaneously after JS is available. Here is what I am looking for:
- Browser makes a request to
/js/abc.js?userid=12345 - Server parses userid=12345 and adds userid = 12345 to the script
- Server returns the script to user
- Browser parses the script and
useridis set to 12345, then everything is processed normally.
Is there a way to do this with some Apache/Lighttpd extension? Since I can't rely on <script>userid=12345</script> at the begining of the document, as abc.js will most probably be executed before userid=12345 is evaluated.
/js/abc.js?userid=12345then you obviously already have the userid available...profile.phpand I know user ID (I use it to load user name and info), however I use Ajax to pull additional data, like comments, and I need to pass the id with Ajax reqeusts. To do that JS needs to have the id.. Unless.. I just got an idea, I'll try it now.