»
S
I
D
E
B
A
R
«
JavaScript: The simple difference between jQuery’s bind() and live()
Mar 5th, 2010 by admin

This morning I am delving into some JavaScript code, and decided once and for all to find out what exactly the difference was between the two functions: bind() and live(). It turns out, there is a very minor but important difference.

According to the jQuery API documentation, bind( action, function ) is used to give an event to all existing matches. On the other hand, live( action, function ) not only gives the event to all existing matches, but all future matches.

So, concluding my thoughts, if you are doing work where you are adding a lot of things to the page — i.e. using AJAX — that need to have an existing action handler applied to them, then you should stick with live(). Otherwise, learn to love bind().

Nick

JavaScript: Bug using .focus() for legacy coding and FF
Mar 4th, 2010 by admin

Hopefully you have found this article before you bashed your head open with your keyboard; if not, please seek medical help before continuing.

When using the .focus() method today, I came across an issue with Firefox — though, I would assume it is for all legitimate browsers. If you are having trouble getting .focus() working, kindly apply the following code.

setTimeout( function(){document.getElementById('field').focus();}, 10 );

Unfortunately, I have no reason why it works, I merely know that it does work.

Nick

JAVA: Using RNFR and RNTO with FTP
Mar 3rd, 2010 by admin

While trying to create a smart FTP client, I wanted to move a file from one location on the remote server to another. A brute-force method would be to delete the uploaded file, and then re-upload it to the proper directory. For the following reasons, this makes little to no sense.

  • You have wasted the original upload.
  • You will waste time deleting the original file.
  • You will waste time re-uploading the new file.
  • Rinse and repeat for x-number of files.

As a result of the above conclusion, I set off to find out which commands I could use to move the file instead of re-uploading it. Enter RNFR and RNTO. According to http://cr.yp.to/ftp.html, RNFR "asks the server to begin renaming a file." and RNTO "asks the server to finish renaming a file."

Armed with that knowledge, I was still having issues with the RNTO command. My response code kept returning 550 rename: No such file or directory. After many hours of anguish [research too, but it did not help], I finally discovered one key error in my code. I had accidentally added an extra space between my RNTO call and the new location.

RNTO  /usr/new/directory/filename.ext is not the same as RNTO /usr/new/directory/filename.ext

Alas, my many hours of beating my head on my desk came down to one erroneous space.

Nick

»  Substance: WordPress   »  Style: Ahren Ahimsa