Sunday, August 7, 2011

IE7 Error: Expected identifier, string or number

Most developers are suffering from IE7 compatibility issue. Most of the time, we encounters error when doing javascript. One of the error I encountered was "Expected identifier, string or number".

This error is due to IE expecting a data. For the sake of this post, I will use the jcarousel plugin passing the parameters we need.

<script type="text/javascript">
$(document).ready(function() {
    $(".carousel").jCarouselLite({
        visible: 3,
        btnPrev: 'a.prevbtnHome',
        btnNext: 'a.nextbtnHome',
    });
});
</script>

As you can see on the sample JS above, we are passing parameters ending all with comma ",". This approach will actually work on most browsers but not on IE7 and below.

To resolve this, you just need to remove the comma "," on the last parameter.

<script type="text/javascript">
$(document).ready(function() {
    $(".carousel").jCarouselLite({
        visible: 3,
        btnPrev: 'a.prevbtnHome',
        btnNext: 'a.nextbtnHome'
    });
});
</script>

Hope this post helps a lot!

Perl 101: Accessing HTTPS URL via LWP

LWP(Library for WWW in Perl) is a Perl library that you can use to access the URL via back-end. However, accessing the URL via HTTPS needs SSL verification which stops your script from running.

Basically, if you are to access the HTTPS URL via browser, it will prompt you to verify the certificate which you have to accept before you actually be able to access it successfully.

To do it via back-end, we will have to do the same but this time, no interface.

First, we need to do SSL verification on the actual server that you will be using to access the URL, and to do that, we will use LYNX command and save the certificate if prompted.

Please see sample syntax below.

lynx https://example.mydomain.com/myscript.php..

If you don't have LYNX, you can do the normal way by accessing it via the browser. All you need to do is to access the browser of the actual server and save the certificate from there.

To check if successful, try to access the URL again, and you should not be prompted to save the certificate again. Hence, saving certificate is not successful.

Once okay with the certificate, we are now good to use LWP library to access the URL.

Please take note that the libraries below should be installed in your server.
- LWP::UserAgent
- HTTP::Request
- Crypt::SSLeay

The script below will be able to access the HTTPS URL. Hope you like it!

#!/usr/bin/perl
use LWP;

my $url = 'https://example.mydomain.com/myscript.php';
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });
$ua->timeout(60000);

my $res = $ua->get($url);
print "result: $res\n";

1;