I have a web application which is showing data that is recieved from an AJAX request to a PHP script running on the same Server. In my case it's the playback of a spotify player. Because I want that Information to be as up-to-date as possible (in case of a change of the song etc.), my current approach is to send a request every second. Is there a possibility to e.g. send a "data changed"-Trigger from the PHP Server to the Javascript, so that only then the AJAX-Request is triggered, in oder to reduce unwanted traffic for the client? Or is there another approach I'm missing with that this Problem can be solved more elegantly?
Well since it's not a production product and just for personal use, what you could do is on:
The JavaScript UI: make the call like you're doing now once. On completion, make the call again (success, error, timeout).
The server side: Remember what the last song was, when you get a new song (comparing to previous) send that back though the open AJAX call.
Basically it will act like a web socket and have a request open all the time to the server. This is not good design, but the quick and dirty to get your pet project going without having to restructure it to use web sockets.