jQuery: The Write Less, Do More JavaScript Library

Best Practise || General Opinion

View: New views
4 Messages — Rating Filter:   Alert me  

Best Practise || General Opinion

by Dave Maharaj :: WidePixels.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

When creating a link that will be used for an Ajax request what is the best way to set the url in the page code?
 
I have seen people say use the href '#' in the html code but then i end up having to use div names and id's and joining them up to create urls like /manage/profile/456789
 
I mean i could make the div id = manage_profile_456789 and then do a replace _ with / and presto there is my url.... but why do all that?
 
If its best to use # can someone explain the reason for that? And if so how do you build the urls? I have a user account set up where the urls are all dynamic and unique so i have to pull them from somewhere and build the url which is really quite a pain.
 
What is wrong with defining the url as you normally would in the html and set the click to return false; and pass the url by
var this_url = $(this).attr('href');
 
Thanks for your opinions.
 
Dave

Re: Best Practise || General Opinion

by Sam Sherlock :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

using $(this).attr('href'); is what I aim for as the page works when jquery dom ready is not used

to me this is the most karmic & simple approach

- S




2009/11/6 Dave Maharaj :: WidePixels.com <dave@...>
When creating a link that will be used for an Ajax request what is the best way to set the url in the page code?
 
I have seen people say use the href '#' in the html code but then i end up having to use div names and id's and joining them up to create urls like /manage/profile/456789
 
I mean i could make the div id = manage_profile_456789 and then do a replace _ with / and presto there is my url.... but why do all that?
 
If its best to use # can someone explain the reason for that? And if so how do you build the urls? I have a user account set up where the urls are all dynamic and unique so i have to pull them from somewhere and build the url which is really quite a pain.
 
What is wrong with defining the url as you normally would in the html and set the click to return false; and pass the url by
var this_url = $(this).attr('href');
 
Thanks for your opinions.
 
Dave


Re: Best Practise || General Opinion

by James-279 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If you could just use:
    var this_url = $(this).attr('href');

Then that would be recommended. This is assuming that if the user has
Javascript disabled, and clicking and following through the on the
link (non-AJAX) would also achieve the same or similar result as
through the AJAX route.


On Nov 6, 12:26 pm, "Dave Maharaj :: WidePixels.com"
<d...@...> wrote:

> When creating a link that will be used for an Ajax request what is the best
> way to set the url in the page code?
>
> I have seen people say use the href '#' in the html code but then i end up
> having to use div names and id's and joining them up to create urls like
> /manage/profile/456789
>
> I mean i could make the div id = manage_profile_456789 and then do a replace
> _ with / and presto there is my url.... but why do all that?
>
> If its best to use # can someone explain the reason for that? And if so how
> do you build the urls? I have a user account set up where the urls are all
> dynamic and unique so i have to pull them from somewhere and build the url
> which is really quite a pain.
>
> What is wrong with defining the url as you normally would in the html and
> set the click to return false; and pass the url by
> var this_url = $(this).attr('href');
>
> Thanks for your opinions.
>
> Dave

RE: Re: Best Practise || General Opinion

by Dave Maharaj :: WidePixels.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The site requires JavaScript and all Ajax requests are checked so if someone
tries to access a link that’s supposed to be Ajax by "open link in new tab"
or typing it directly into browser they get redirected to some page so Ajax
content is only accessed by Ajax requests.

Thanks for your insight guys.

Dave

-----Original Message-----
From: James [mailto:james.gp.lee@...]
Sent: November-06-09 7:27 PM
To: jQuery (English)
Subject: [jQuery] Re: Best Practise || General Opinion

If you could just use:
    var this_url = $(this).attr('href');

Then that would be recommended. This is assuming that if the user has
Javascript disabled, and clicking and following through the on the link
(non-AJAX) would also achieve the same or similar result as through the AJAX
route.


On Nov 6, 12:26 pm, "Dave Maharaj :: WidePixels.com"
<d...@...> wrote:

> When creating a link that will be used for an Ajax request what is the
> best way to set the url in the page code?
>
> I have seen people say use the href '#' in the html code but then i
> end up having to use div names and id's and joining them up to create
> urls like
> /manage/profile/456789
>
> I mean i could make the div id = manage_profile_456789 and then do a
> replace _ with / and presto there is my url.... but why do all that?
>
> If its best to use # can someone explain the reason for that? And if
> so how do you build the urls? I have a user account set up where the
> urls are all dynamic and unique so i have to pull them from somewhere
> and build the url which is really quite a pain.
>
> What is wrong with defining the url as you normally would in the html
> and set the click to return false; and pass the url by var this_url =
> $(this).attr('href');
>
> Thanks for your opinions.
>
> Dave