Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mick79's avatar

Get PHP variables via AJAX call to controller and insert them into HTML?

I feel like this should be straight forward, but I'm struggling with it.

My app plays audio files. As such I have a list of sources to the files that are made up of various dynamic parts eg

{{$Url}}?policy={{$policy}}&signature={{$signature}}

The above, when rendered looks something like this:

https://cdn.mycdn.com/7Ap219k0TTmiQLric24S?policy=eyJleHBpcnkiOjE2MjA1OTg4NDh9&signature=f2100a68da21bc627a5249373a9fd2eff13435efce27a9013d09cc60187e50b4

I only want to generate the $policy and $signature parts at the moment the user clicks the PLAY button.

I already have an onclick function that is doing some other AJAX stuff such as updating play counts but I also want - at the moment of clicking "play" - to hit a controller, generate those $policy and $signature variables and insert them into the audio source.

Could someone point me in the right direction here. Like I said, I feel like this should be straightforward but my head just isn't working tonight.

0 likes
2 replies
Mick79's avatar

I have got the variables returning correctly. I can't figure out how to update the source URL with $policy and $signature.

Mick79's avatar

All good. Sorted this on my own.

Just needed a good talk with myself.

Please or to participate in this conversation.