开发者

Why does this code post data twice?

Why does this code post data twice ?

$.post("sen开发者_如何学Cd/user/sent.php", { url: response, secret_key: secret_key },
function(data) {
    if (parseInt(data.succ_code) == 0){
        // facebook log fired successfully
        $('#sent').addClass('good');
        $('#sent').html(data.succ_mess+' '+data.point+' point(s) !');
        return true;
    } else {
        $('#sent').html(data.succ_mess);
        $('#sent').addClass('bad');
    }
}, 'json');

In the database I see two rows for every post.

But if I do this:

$.post("send/user/sent.php", { url: response, secret_key: secret_key },
function(data) {
        // facebook log fired successfully
        $('#sent').addClass('good');
        $('#sent').html(data.succ_mess+' '+data.point+' point(s) !');
        return true;
}, 'json');

The data is just sent one time (good).

Can I make the if statement in $.post() success result without this happening?


Here is some code you might want to use:

$.post("send/user/sent.php", { url: response, secret_key: secret_key },
    function(data) {
        switch (parseInt(data.succ_code)){
        case 0: $('#sent').addClass('good').html(data.succ_mess + ' ' + data.point + ' point(s)!'); break;
        default: $('#sent').addClass('bad').html(data.succ_mess); 
        }
    }, 'json'
);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜