-1

I've encountered a small problem building a web application.

My thinking was simple: application [web music player] reads $_POST['itemId'] every time it is loaded. If it does not exist, the player doesn't start playing a song, but idles, otherwise it plays a song with itemId.

Now the problem comes here:

when a song in a playlist is finished, I'd like to refresh the page and send incremented itemId via post request, so the server side will know which song I'm currently listening to. I've searched the internet for possible solutions how to refresh a page and send post data at the same time, but all I've found are Ajax tutorials.

A working solution would be sending a form every time I'd like to load a new song, but it seems quite a messy one, so I'd like to know if anybody had done that before.

Codemwnci
  • 51,224
  • 10
  • 90
  • 127
usoban
  • 5,225
  • 23
  • 39
  • 2
    Is there any specific reason why you can't/won't use Ajax? – Wolph Dec 19 '10 at 13:53
  • I think to have a post request you must have a form submitted – Nettogrof Dec 19 '10 at 13:56
  • @WoLpH: I'd like to refresh the whole page at once, since other parts of page also rely on updated itemId. – usoban Dec 19 '10 at 13:57
  • Web music player plays a song at *client*. While form being sent to the server. Go figure. – Your Common Sense Dec 19 '10 at 13:59
  • 1
    @Nettogro: Not necessarily, you can also send a POST request via AJAX – nico Dec 19 '10 at 14:00
  • @Col. Shrapnel: sure it does play at client, but server has to tell client where the song is located, it scrobbles to last.fm, updates play count, it has to send song lyrics to client, etc. That's why I need the right itemId every time the song changes ;) – usoban Dec 19 '10 at 14:01
  • you've been told thousands times already - ajax. – Your Common Sense Dec 19 '10 at 14:03
  • And I will tell you once again, Ajax is no good for me in this situation, for very specific reasons. – usoban Dec 19 '10 at 14:07
  • Ajax is so lightweight and perfectly suited for this kind of task. What are your reasons to not use it again? – Felix Kling Dec 19 '10 at 14:25
  • I really don't understand the scenario you are describing here. But you can update as much or as little of a page, or different parts of a page, with ajax via GET or POST requests. – Richard H Dec 19 '10 at 14:36
  • Had you used youtube before ? Does youtube playlist use POST for the solution ? (use GET please ...) – ajreal Dec 19 '10 at 14:37
  • The reason is I must have a lot of parts of a page updated at the same time, no waiting for ajax request to get loaded. And just imagine having a page opened for an hour and every three minutes 15 ajax requests flying around. – usoban Dec 20 '10 at 09:53

1 Answers1

2

If you really have to refresh the page using post (although I would advise against it, this sounds much more like something you would use AJAX for).

<form id="form" method="post" action="some_url">
    <input type="submit" value="Refresh">
</form>

<script type="text/javascript">
    document.getElementById('form').submit();
</script>
Wolph
  • 69,888
  • 9
  • 125
  • 143
  • Well that is the first helpful answer here. After reading your post, I found the solution here: http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit Thank you. – usoban Dec 20 '10 at 09:51