views:

1801

answers:

2

I have this code in JQuery:

$().ready(function() {
{exp:weblog:entries weblog="locations" show_expired="yes" show_future_entries="yes" orderby="date" sort="desc" limit="5" rdf="off" disable="member_data|trackbacks" status="open|featured|ongoing"}
$('a.Favorites_Trigger_{entry_id}') .click (function() {
$.get(this.href, function(data) {
$('span.favoritesspan_{entry_id}').html(data);
$('dl.favoritesul > dd.entry_{entry_id}').replaceAll('dl.favoritesul > dd.entry_{entry_id}');
});
return false;
});

What I am trying to do: when a link is clicked it currently updates a database in the main part of my page (call it widget.php), now widget.php also has a side bar where I want to show the new results of the triggered event that just took place. I click a link to say add or delete this favorite. It's basically a "my favorites" php module but I cannot seem to get the updated results once the link is clicked ever though the database change happens, I see that upon hard refresh of the browser. So is it possible to have that part refresh JQuery style?

A: 

Your entry ID may not be working the way you expect because the template tags you're using are rendered on the server before being sent to the client. This means that if you view source in the browser, your resulting JQuery code is going to have a single hard coded value in place of the {entry_id} tag you're using. That means, in theory, the JQuery code is only working on either the very first, or very last entry, depending on how the templates are processed.

What you need to do is have your JQuery code act more generically. Simply have it refresh the list form your database when, say, anything called a.favourites_trigger is clicked.

If you can post a working example, it might make things easier.

Soviut
A: 

Thanks for the answer Soviut. It's actually for an Expression Engine Module and it calls the function to add/delete via click in file one and in file two it add or deletes function. The side bar is pulling the results, I'll call that file three. Thanks for taking a look.

Code is below:

File One:

{if logged_in}
{exp:favorites:saved entry_id="{entry_id}"}
{if saved}
<span class="favoritesspan_{entry_id}"><em>Saved as a favorite.</em>&nbsp;<a class="Favorites_Trigger_{entry_id}" href="{path='features/favorite-add/'}{entry_id}/delete">Remove from favorites list?</a></span>
{/if}
{if not_saved}
<span class="favoritesspan_{entry_id}"><a class="Favorites_Trigger_{entry_id}" href="{path='features/favorite-add/'}{entry_id}/add">Add this item to your favorites?</a></span>
{/if}
{/exp:favorites:saved}
{/if}

File Two: (processor)

{exp:favorites:save weblog="funxyz"}

File Three:

    <dl class="favoritesul">
    {exp:favorites:entries weblog="funxyz" show_expired="yes" show_future_entries="yes" dynamic="off" status="open|featured|ongoing"}
<dd class="entry_{entry_id}">{title}</dd>
{/exp:favorites:entries}
    </dl>
dvancouver