jQuery: “missing : after property id” Error

I didn’t realize how rusty one could get in just a week!

This is the code I was trying to use — a function I’ve used hundreds of times — and I kept getting the “missing : after property id” error.

$(document).ready({
});

Did you catch it? Neither did I ;-)

Well, according to the jQuery API the .ready() function takes a function — do you see my error now?

$(document).ready(function() {
});

Kudos to user113716 for [indirectly] pointing out my flaw, and with that silly bug I’m off to get another cup of caffeine.

Nick

TinyMVC: PDO & UTF-8 Character Set

When setting up the initial model for a TinyMVC project, I got the following error:

Message: Can’t connect to PDO database ‘mysql’. Error: SQLSTATE[HY000] [2019] Can’t initialize character set UTF-8 (path: /usr/share/mysql/charsets/)

After looking in /path/to/tinymvc/sysfiles/plugins/tinymvc_pdo.php I noticed the following on line 95:

    if(empty($config['charset']))
        $config['charset'] = 'UTF-8';

Since nothing appeared wrong, I did a quick Google search and found this bit of information:

Just tried your recommendation on the other server with php 5.3.6 and it worked with utf8 versus utf-8. Just to double check i tried it again with utf-8 and that didn’t work

So, armed with that knowledge, I updated /path/to/tinymvc/sysfiles/plugins/tinymvc_pdo.php to read as:


    if(empty($config['charset'])) {
        $config['charset'] = 'UTF8';
    }

Bingo! After saving the file and refreshing, the error was gone!

Nick

HTML and JavaScript: Safari and Loading Files

Today I experienced an odd issue with Safari. It appears as though the HTML attribute defer=”defer” is not translated by Safari. Below are two examples of code. The former was what worked in every major browser except Safari. The latter works in all browsers that I have tested.

<script type=”text/javascript” defer=”defer” src=”/js/file2.js”></script>
<script type=”text/javascript” defer=”defer” src=”/js/file3.js”></script>
<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js”></script>
<script type=”text/javascript” defer=”defer” src=”http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js”></script>
<script type=”text/javascript” defer=”defer” src=”/js/file1.js”></script>

<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js”></script>
<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js”></script>
<script type=”text/javascript” defer=”defer” src=”/js/file1.js”></script>
<script type=”text/javascript” defer=”defer” src=”/js/file2.js”></script>
<script type=”text/javascript” defer=”defer” src=”/js/file3.js”></script>

The reason that the former was in that order was because of the way that Zend loads files via prependFile() and appendFile(). Using the proper combination of the two functions, I was able to get them into the desired order.

Nick

PHP: cURL and htpasswd [apache auth]

After spending literally all afternoon working on it, here an example of the code I finally got to work!

curl_setopt( $this->_curlHandle, CURLOPT_URL, ‘site.com/password-protected’ );
curl_setopt( $this->_curlHandle, CURLOPT_USERPWD, ‘username:password’ );
curl_setopt( $this->_curlHandle, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $this->_curlHandle, CURLOPT_HTTPAUTH, CURLAUTH_ANY );
$result = curl_exec($this->_curlHandle);

I have bolded the part that was the culprit! I hope this saves you time [and your company money ;-) ].

Nick

JavaScript: Defining Arrays in Succession

Quite literally two hours later and I finally figured out how JavaScript handles defining arrays in succession. The issue was that I was getting the same values for array’s defined in succession — aka on the same line — even though they had different index names.

Below is an example of my code:

var $array = new Array();
$array[0] = $array[1] = new Array();

$array[0][0] = ‘hello’;
$array[0][1] = ‘world’;

console.log($array[0][0]); // ‘hello’
console.log($array[1][0]); // ‘hello’

The underlining issue with this code is that when defining array’s in succession the array indices will share the same memory reference; in PHP — my native language — it defines a separate memory reference for each array.

Nick