Monday, May 24, 2010

Can Perl be used for AJAX?

I'm trying to make a game for the internet browser, that is multiplayer, so I'm using Ajax. The client side script is working fine, I think. But every time i reuse a Server Side script (which is written in Perl because that is the only server side script i know), it gives the same result as the last time, even if i refresh the page. Is there something I'm missing?

Can Perl be used for AJAX?
hey man you can use any language u want for ajax. and now the problem you were describing, It could be that the browser is just fetching the reply from your cache. Are you using a random seed every time to avoid this problem.


in ajax when submitting the url it should be something like this.


url = "somepage.pl?data=asd%26amp;random=" + Math.random();


this will append a random number on to the end of the url so that the browser does not fetch the reply from the cache.
Reply:Perl can be used for the backend to an AJAX application, yes. AJAX only defines the client-side technologies - in this case, JavaScript, via an XMLHttpObject. The back end (Server side) doesn't matter, it could even be static HTML. What I would do is check the Perl page manually first, before trying it in an AJAX environment.





Also, I know from experience that when using IE with AJAX, it will reload pages with the one in cache even if the content should be different. The solution for this is to append a unique GET variable to the URL of the page you're loading in AJAX. I use a timestamp, that's easiest (you could also use a random number, but then you have problems if the number appears again). A workaround for this is to test using Firefox, which doesn't seem to suffer from this caching problem.


No comments:

Post a Comment