samedi 27 juin 2015

Jquery Add Argument to Function on $.ajax

I want to return my button value if ajax failure.

This HTML (on PHP):

<a href="javascript:void(0);" id="follow-topic" value="7">
    <button class="btn btn-xs btn-primary pull-right"><?php echo $_LANGS['forum']['follow']; ?></button>
</a>

This JS (on PHP):

    $("#follow-topic").click(function(event) {
        var topicid = $(this).attr('value');
        var button_follow_html = $(this).html();
        if ($(this).is("a[disabled]")){ return false; }
        $("#follow-topic button").html('<?php echo $_LANGS['system']['loading_button']; ?>');
        $(this).attr({ disabled: true});
        $.ajax({
            url: "",
            data: { follow_topic: topicid },
            type: "POST",
            success: function (data) {
                $("#follow-topic").html(data);
                $("#follow-topic").attr({ disabled: false});
            },
            error: function(data, button_follow_html) {
                handleRequestError(data);
                $("#follow-topic").attr({ disabled: false});
                $("#follow-topic").html(button_follow_html);
            }
        });
    });

I've change a button value to $_LANGS['system']['loading_button'] but i want return to $_LANGS['forum']['follow'] if ajax failure or client lost connection.

This system using multiple languages and if ajax is success, button will be replaced to followed button so i can't use $("#follow-topic button").html('<?php echo $_LANGS['forum']['follow']; ?>');.

Sorry for My English and Thank you

Aucun commentaire:

Enregistrer un commentaire