Javascript Posts

Weird HTTP Error, HTTP Request Parameter Not Detected When Using JavaScript canvas.toDataURL and Base64 Ajax Post

I have a simple Java web application that use Ajax image upload using canvas.toDataURL and base64 encoder. Usually it run well, but I have a very weird error that happen intermittently. Somehow my application cannot detect any http request parameters that send by my Ajax requests. After I spend a while researching, it seems that this error only happen when uploading multiple big images.

At first I thought that it was my Java or JavaScript issue, but then I realized that this is an issue on my Application Server, which is Apache Tomcat. Its default value for maximum POST size is 2MB (2097152), and after I resize it, the error went away.

I add “maxPostSize” property on server.xml, to increase maximum POST size that Apache Tomcat can handle. In this example, i increase it into 20MB.

    <Connector connectionTimeout="20000" 
        port="8080" protocol="HTTP/1.1" 
        redirectPort="8443" maxPostSize="20971520"/>

;-)

Google+

[Weird Javascript Error] Leading Zero on Integer Variable Become Octal on Old Browser

Ive met a very weird error, that somehow never occurs to me on my browser. I found this error only happen on old mozilla browsers, and only happen on javascript’s parseInt method. Here is a simple example,

alert(parseInt("09")-1);

When im running it on my browser (Mozilla version 34), this is what happen,
mozillanew

But when running on old browsers (Mozilla version 3.6), this is what happen,
mozillaold

I finally found out that that on old browsers, leading zeros are treated as octal values instead of plain integers. So this is my workaround,

alert(parseInt("09".replace(/^[0]+/g,""))-1);

I removed the leading zero before parsing it into int.

Hope it can help others :)

Google+

Creating a Calendar or Date Picker using JQuery

Well, it’s actually quite easy to create a simple calendar or datepicker using jquery. But first you need to download jQuery and jQuery UI libs. This is how you do it,

<html>
    <head>
        <title>JQuery Test</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="datePicker.css" type="text/css" rel="stylesheet" />
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="jquery-datepicker.js"></script>
        <script type="text/javascript">
            $(function()
            {
                $('#date-pick').datepicker({
                    showOn: "button",
                    dateFormat: "dd/mm/yy",
                    disabled: true,
                    buttonImage: "calendar.png",
                    buttonImageOnly: true
                });
            });
        </script>
    </head>
    <body>
        Enter your birthdate :
        <input name="date1" type="text" id="date-pick" size="10" maxlength="10" />
    </body>
</html>

It will look like this,

For the live example, you can see here. Cheers (B)

Google+