Eric on 29 Jan 2009 07:26:00 -0800


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] OT: Javascript question


Douglas:

Thanks for the info:


Douglas Muth wrote:
> On Wed, Jan 28, 2009 at 11:50 PM, Eric <eric@lucii.org> wrote:
>   
>> Not sure where to go with this... it's not really liunx although I'm
>> developing it on a Linux system :-)
>>     
>
> I don't know the cause of the problem, but I can tell you that the
> approach you are taking is unnecessarily complicated, and not making
> full use of what jQuery has to offer.  To wit:
>   
True.  I'm relatively inexperienced with JavaScript and I just found jQuery
so I'm a novice as far as jQuery goes.
> 1) You don't need to loop through all of the links once they're
> created.  Use jQuery's selectors to do it for you. aka:
>
>  $("#outer_div_id").find("a").each(function() {
>    // Code goes here
>    });
>
> Alternatively, you could set a style class for all of the links you
> create, and iterate through them like this::
>
> $(".class_type").each(...
>   
I would love to do that but each function has a different URL and I'm
not sure how I'd get the right URL with the right text using these methods.
I'll work on it though as it sure beats what I'm doing now. 

By the way I got the code I originally posted to work by removing it
from the loop and placing it in a series of IF statements.  It was a
test to see if the loop was somehow broken or the concept was broken.
Now that I know that I can get it to work I'll check out your suggestions.

> 2) Don't use bind(), use click(), aka:
>
> $(element).click(function() {
>    // Code
>    });
>   
Noted. 
> 3) Don't use loadXMLDoc(), use jQuery's $.get() function or similar.
>   
I had already written (adapted, actually) the loadXMLDoc() functionality
before starting to use jQuery.  As soon as I can figure out how the $.get()
stuff works I'll be scrapping my old code.  Actually, I'll probably have to
use $.post() because I use session info to authenticate the user's request
with the ajax server process.   That might not be the best way but it was
the only way I could think of to enforce security like I do on the rest of
the site.
> You might want to spend some time brushing up on all that can be done
> with jQuery, by looking at the "API Reference" section under
> http://docs.jquery.com/Main_Page, as well as www.visualjquery.com.
>   
I have the API Reference bookmarked and www.visualjquery.com looks
cool.

The AJAX related stuff is particularly opaque to me as they list a bunch
of functions but don't tell you which ones you need to implement a
working AJAX application.  I'm sure once I go through a few  of the
tutorials I'll be amazed.

> -- Doug

Thanks again!

Eric

-- 
#  Eric Lucas
#
#                "Oh, I have slipped the surly bond of earth
#                 And danced the skies on laughter-silvered wings...
#                                        -- John Gillespie Magee Jr

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug