views:

26

answers:

2

Hi,

I implemented a thumpsup function in php. the view holds a thumpsup button and everytime the user clicks on it the db is updated. I am working with zend framework, so I have a url mypage.de/articles/thumpsup/id/x this url points to a specific acion/function in my articles conroller, but this function does not return any data, it just adds the thumpup to the database. there is another function list that passes content to the view.

so I am looking for a jquery function that executes the query url mypage.de/articles/thumpsup/id/x on click and then executes the list function to refresh the view.

$(document).ready(function() {
    $("a.tp").click(thumpsUp);
});

function thumpsUp() {
var url = window.location.hostname + '/articles/thumpsup/id/'
        + $(this).attr('id');
$.post(url, {
    "format" : "json"
}, function(data) {
    ....
}, 'html');
return false;
}

so the function thumpsup which I would normaly use to execute a url and update the view does not work here. any ideas how to solve that?

+1  A: 

if you are using $(this) then you need to pass it to the function AND you can't just run a function, you need an anonymous function... so try this:

$(document).ready(function() {
    $("a.tp").click(function(){ var myelement = $(this); thumpsUp(myelement); });
});

function thumpsUp(element) {
var url = window.location.hostname + '/articles/thumpsup/id/'
        + element.attr('id');
$.post(url, {
    "format" : "json"
}, function(data) {
    ....
}, 'html');
return false;
}
Thomas Clayson
with $(this).attr('id') I am just getting the article id from the article link. but that was not my problem^^. I want to know how to implement a function that in a asnyc way writes a thumpup into the database without returning any content
ArtWorkAD
oh I'm not sure I understand. If you just return plain text "success" or similar will it not work? You can ignore `data`.
Thomas Clayson
A: 
Thomas Weber