jQuery : Error: $(document).ready is not a function
Yes it bloody is!
Quite often when I’m mucking about with WordPress firebug will throw the following error:
jQuery : Error: $(document).ready is not a function
If you see this error it’s because another framework is in conflict with jQuery – most usually in my case it’s mootools or scriptaculous, anyway here’s the work-around.
The people who developed jQuery had the foresight to include a function which makes jQuery play nicely with other frameworks which all use the $ sign as a staple part of their code. Introducing the jQuery.noConflict(); function.
The jQuery.noConflict(); command you can replace the $ sign with the word jQuery throughout your code.
So, for example, instead of using the normal dom ready function: $(document).ready(function() you would use: jQuery(document).ready(function() just don’t forget to call the .noConflict function before this, so the whole shebang would look like this:
<script src=”mootools.js”></script> // this is the conflicting framework
<script src=”jquery.min.js”></script> // this is your jQuery
<script>
jQuery.noConflict(); // start substituting $ for jQuery
jQuery(document).ready(function(){
jQuery.yourjQueryfunctions();
});
</script>
instead of:
<script src=”mootools.js”></script>
<script src=”jquery.min.js”></script>
<script>
$(document).ready(function(){
$.yourjQueryfunctions();
});
</script>
- <script src=“prototype.js”></script>
- <script src=“jquery.js”></script>
- <script>
- jQuery.noConflict();
- jQuery(document).ready(function(){
- jQuery(‘div’).stuff();
- //notice, that the $sign has been replaced with the word jQuery
- });
- // And you can use Prototype with $(…)
- $(‘id’).hide();
- </script>
[for work] newsletter and poster design -v-
a replacement for file_get_contents
The newer versions of PHP has disallowed the use of file_get_contents(especially when you are using a hosted environment). here’s a quick work around for this issue, include the following class in your code
<?php
class CA_HTTP {
public static function get_contents($url) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);
curl_close ($ch);
return ob_get_clean();
}
}
?>
and use it like the following:
<?php
class CA_HTTP {
public static function get_contents($url) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);
curl_close ($ch);
return ob_get_clean();
}
}
?>
Newletter design
[facebook code]Check if the user liked your page…
function parsePageSignedRequest() {
if (isset($_REQUEST['signed_request'])) {
$encoded_sig = null;
$payload = null;
list($encoded_sig, $payload) = explode(‘.’, $_REQUEST['signed_request'], 2);
$sig = base64_decode(strtr($encoded_sig, ‘-_’, ‘+/’));
$data = json_decode(base64_decode(strtr($payload, ‘-_’, ‘+/’), true));
return $data;
}
return false;
}
if($signed_request = parsePageSignedRequest()) {
if($signed_request->page->liked) {
echo “This content is for Fans only!you can see this message:)”;
} else {
echo “Please click on the Like button to view this tab!”;
}
}
?>
can connect to localhost but not phpmyadmin(socket configuration)
Error description:user can use 127.0.0.1 to get into the default page but while connect to 127.0.0.1/mysqladmin, user will encounter a “socket configuration wrong” error.
to solve this, just find the following file,
wamp->apps->phpmyadmin3.3.5->config.inc.php
change
$cfg['Servers'][$i]['verbose'] = ‘localhost’;
$cfg['Servers'][$i]['host'] = ‘localhost’;
to
$cfg['Servers'][$i]['verbose'] = ‘127.0.0.1′;
$cfg['Servers'][$i]['host'] = ‘127.0.0.1′;
UTF8 encoding not displaying properly?
Open the web page file in notepad, click “save as”, choose “utf-8″ as its encoding instead of ANSI, “save as” file type set to “all files”
–Done!
PHP mail sending encoding problem
While using PHP mail() function, if the mail contains non-alphabetical characters, use the following function for a correct display of characters.
<?php
function mail_utf8($to, $subject = '(No subject)', $message = '', $header = '') {
$header_ = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n";
mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header);
}
?>
Faith
I used to think, Faith means “I believe that God will do something for me(something I want)”.
But actually faith means,”believe in what God will do for you”.
The real faith will never fail, because it makes you accept whatever you face.
It sounds like “im a dead pig anyway so boil me” kind of speech, but I believe our attitude should be more like “since it happened already, let us not be discouraged and strive for something better to come”.
I was thinking about this when I was on the bus.




