Read the latest web development and design tips at Fred Wu's new blog! :-)
Poke me on GitHub

Archive for the ‘Javascript / AJAX’ Category

jQuery problems in IE? It could be SWFObjects.

So your jQuery/JavaScript code doesn’t have any errors, yet your site isn’t working as expected in Internet Explorer? It could be that you have some SWFObject code interfering with your jQuery code (if for example, you’re using a Flash video player or something along those lines). The solution is very simple. Simply enclose your SWFObject code in a jQuery $(document).ready() as so:

<script type="text/javascript">
    $(document).ready(function(){
        var so = new SWFObject("movie.swf", "mymovie", "400", "100%", "8", "#336699");
        so.addParam("quality", "low");
        so.addParam("wmode", "transparent");
        so.addParam("salign", "t");
        so.write("flashcontent");
    });
</script>

The only downside to this is that if you have some alternate HTML to show when Flash isn’t present, this text will be shown until the document is fully loaded and the player(s) start to render (even if the user does in fact have Flash installed).

Related posts

json_encode() for PHP4 and early PHP5

Had a beauty today. There I was ready to deploy some nicely polished code to the server. After some thorough local testing it looked like it’d be a smooth process. So the code went up, but all my funky AJAX stuff stopped working on the server. How could that be? It was perfect locally… :)

It took a little while but in the end I realised what was going on – json_encode wasn’t working. The server was running PHP 5.1.6 and json_encode only became “standard” with PHP 5.2.0 onward.

I needed a solution fast. No time to recompile a newer version of PHP, add libraries or anything fancy like that. I just needed the function json_encode to work right now. Thankfully, the solution was as easy as adding replacement a function a user kindly submitted from the PHP site itself:

http://au.php.net/manual/en/function.json-encode.php#82904

I blindly assumed PHP 5 was PHP 5. I wasn’t using any extremely fancy commands or anything, but I still came unstuck. So the moral of today is check your server specification right down to every last decimal point! ;)

Related posts