开发者

jQuery, DB Update/Display Problem

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开发者_JAVA百科.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?


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;
}


If I understand you correctly the "list" function is also JavaScript. If that's the case, simply call it from the callback function of your AJAX request.

function(data) { $.post(url, { "format" : "json" }, function(data) { list(); }, 'html');

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜