Oh please please please, help me … How to get the entry id into a js/ajax link? 
Posted: 02 June 2007 04:11 AM   [ Ignore ]
Newbie
Rank
Total Posts:  29
Joined  2006-09-16

Hello again,

I think I’ve been sitting here for the past 14 hours trying to figure out how to get the favorites module used with Ajax. This is driving me crazy. :-(

I am using jQuery for my JavaScript/Ajax needs but I’m a total beginner by all means and on every end.

Anyway, I hope (if I prayed, I’d have said I pray! But I don’t, so this will have to do) that any of you masters of the trade can help me in my effort to get this to work.

The task seems simple. I would like to have a dialog box appear upon clicking the appropiate link with the succes/error message that is stored in a template of its own.

I did manage to get as far as having the message display, “An entry id must be provided”. And I think this is where my problem seems to lie. I do not know for the life of me how I can make the entry_id get recognized by the ajax call.

So, here is the JavaScript code I am using:

$().ready(function() {
  
  
// select + reference "triggering element" -- will pass to $.jqm()
  
var triggers = $('a.ex3bTrigger')[0];
  
  
// NOTE; we could have used document.getElementById(), or selected
  //  multiple elemets with $(..selector..) and passed the trigger
  //  as a jQuery object. OR, just include the string '#ex3btrigger'
  //  as the trigger parameter (as typically demonstrated).
  
  //  NOTE; we supply a target for the ajax return. This allows us
  //   to keep the structure of the alert window. An element can
  //   also be passed (see the documentation) as target.
  
  
$('#ex3b').jqm({
    trigger
: triggers,
    
ajax: '/classifieds/favorite_add/' + $('a[@id=entry_id]'),
    
target: 'div.jqmAlertContent',
    
overlay: 0
    }
);
  
  
// Close Button Highlighting. IE doesn't support :hover. Surprise?
  
if($.browser.msie) {
  
$('div.jqmAlert .jqmClose').hover(
    function()
{ $(this).addClass('jqmCloseHover'); },
    function()
{ $(this).removeClass('jqmCloseHover'); });
  
}
}
);
</script>

Then I have the div that should display the success/error message

<div class="jqmAlert" id="ex3b">

<
div id="ex3b" class="jqmAlertWindow">
    <
div class="jqmAlertTitle clearfix">
    <
h1>Did you know?</h1><a href="#" class="jqmClose"><em>Close</em></a>
  </
div>
  
  <
div class="jqmAlertContent">
  <
p>Please wait... <img src=".../images/loading.gif" alt="loading" /></p>
  </
div>
</
div>

And here is the link:

<a href="{path='/classifieds/favorite_add'}{entry_id}" class="ex3bTrigger" id="{entry_id}">Add</a>

I will explain what I have done.

1. assign the entry id to the anchor that will be clicked: id="{entry_id}”
2. construct the URL within Ajax: ajax: ‘/classifieds/favorite_add/’ + $(’a[@id=entry_id]’), (obviously horribly wrong). When I remove everything after the slash, it works, albeit outputs the error message I listed above ("An entry id must be provided").

The gist (I think) is that I need to find out how I can append the entry_id or url_title to the link.

I am hoping that some of you may have worked with the module in conjunction with jQuery or simply know 16 tons more of what I know.

Thanks a ton,

Maleika

PS: I am also willing to pay if anyone can help me understand this or is even willing to take a look at my code.

Profile
 
 
Posted: 02 June 2007 08:51 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  701
Joined  2004-03-30

I’ll try an give you more help in a few hours, but for now go to macitt.com and have a look at how Favorites are handled there. Whereever you see this

macitt +

That’s the favorite module in action.

Also see ssireview.org in the article section. The favorites functionality is working there too.

mk

 Signature 

Mitchell Kimbrough

Profile
 
 
Posted: 02 June 2007 12:01 PM   [ Ignore ]   [ # 2 ]
Sr. Member
Avatar
RankRankRankRank
Total Posts:  336
Joined  2005-07-09

Maleika, I didn’t go through your code line by line, but all the Favorites module requires is an entry id in the calling URL. You know that, of course.

Maleika - 02 June 2007 04:11 AM

<a href="{path='/classifieds/favorite_add'}{entry_id}" class="ex3bTrigger" id="{entry_id}">Add</a>

Could you humor me and try doing without “{path}” for once? Let’s hardcode the URL:

<a href="/classifieds/favorite_add/{entry_id}" class="ex3bTrigger" id="{entry_id}">Add</a>

Does that change anything? Also, Mitchell gives good advice, of course.

 Signature 

Ingmar Greil

Profile
 
 
Posted: 02 June 2007 08:42 PM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  701
Joined  2004-03-30

Maleika,

Checking in again. I feel you on jQuery. Chris Ruzin, one of the super geniuses often in residence at Solspace swears by it. And I have seen several miracles worked by he and it. However, I still haven’t gotten the hang of it. I know Prototype like the back of my hand. That’s what we use on Macitt. Prototype has a function called Ajax.Updater() that I execute for the onclick event on my links. It updates the contents of the indicated element id on the page with the contents of the url you provide it. And in Favorites, this URL would be to the template on your site that contains {exp:favorites:add}

The code would be this simple:

onclick="new Ajax.Updater(’some_element_id’, ‘some_url’);”

mk

 Signature 

Mitchell Kimbrough

Profile
 
 
Posted: 02 June 2007 09:45 PM   [ Ignore ]   [ # 4 ]
Newbie
Rank
Total Posts:  29
Joined  2006-09-16

Thank you both for your advice. I will go through these. Thanks!

Maleika

Profile
 
 
Posted: 06 June 2007 02:28 PM   [ Ignore ]   [ # 5 ]
Newbie
Rank
Total Posts:  29
Joined  2006-09-16

I got it to work. My problem was that I did not want to use Prototype. I also wanted to place all behaviour outside the anchor tags, so no onclick etc. inside anchors. Anyway, I now have it working with jQuery and it’s awesome! I will post the solution when I’ve done more testing etc.

Now, I’m going to apply the same magic to the ratings module. grin

Thanks!

Maleika

Profile
 
 
Posted: 06 June 2007 02:47 PM   [ Ignore ]   [ # 6 ]
Sr. Member
Avatar
RankRankRankRank
Total Posts:  336
Joined  2005-07-09

Great. Yes please, do share your code once you feel comfortable doing so.

 Signature 

Ingmar Greil

Profile
 
 
Posted: 13 October 2007 04:20 AM   [ Ignore ]   [ # 7 ]
Member
Avatar
RankRankRank
Total Posts:  71
Joined  2006-05-10

Hi there,

Sorry to drudge this up from the past like this but was just wondering if you would possibly share your code on here Maleika or if anyone has any code using any of the JS libraries.

What I would like to be able to do is have a section on a page which lists the persons favorites that they have added to. If they are on an entry and click on an add to favorites link or button then this would be sent using Ajax and would show a message (possibly with a fade?) to say that the entry has been added to their favorites and then for the favorite / entry to appear in their list on the page.

Any help with this would be massively appreciated.

Best wishes,

Mark

Profile
 
 
Posted: 13 October 2007 05:20 AM   [ Ignore ]   [ # 8 ]
Newbie
Rank
Total Posts:  29
Joined  2006-09-16

Mark, I’ll pm you with a link.

Edit: Okay, I meant email. smile

Profile
 
 
Posted: 13 October 2007 08:41 AM   [ Ignore ]   [ # 9 ]
Member
Avatar
RankRankRank
Total Posts:  71
Joined  2006-05-10

Hi there Maleika,

Thanks for the e-mail. Very much appreciated.

Best wishes,

Mark

Profile
 
 
Posted: 13 October 2007 12:17 PM   [ Ignore ]   [ # 10 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  701
Joined  2004-03-30

Thank you Maleika!

mk

 Signature 

Mitchell Kimbrough

Profile
 
 
Posted: 16 October 2007 04:54 AM   [ Ignore ]   [ # 11 ]
Newbie
Avatar
Rank
Total Posts:  5
Joined  2006-06-30

Maleika, can you please email me a link, too?

Profile
 
 
Posted: 18 December 2007 10:13 PM   [ Ignore ]   [ # 12 ]
Member
Avatar
RankRankRank
Total Posts:  55
Joined  2006-09-11

I’m a jQuery fan too, and would love a link emailed or PM’ed to me as well. Anything to save me a few hours of monkeying around. Thanks much.

Profile
 
 
Posted: 11 April 2008 10:10 PM   [ Ignore ]   [ # 13 ]
Sr. Member
RankRankRankRank
Total Posts:  153
Joined  2007-02-19

Just found this thread. Maleika, can you PM me the code (or give me a link) also? I’m toying around with the favorites module as we speak.

PS: remember me from TXP? wink

Profile