成功后,Ajax更改按钮

时间:2018-04-17 08:14:19

标签: jquery prestashop smarty

我尝试在成功的那一刻改变一幅画的按钮。这是我的代码:

我的阵列:

enter image description here

模板:

{foreach from=$statistics.sponsored1 item=sponsored name=myLoop}
                    {assign var="indiceDirect" value="direct_customer`$sponsored.id_customer`"}
                    {assign var="indiceIndirect" value="indirect_customer`$sponsored.id_customer`"}
                    {if isset($statistics[$indiceDirect])}
                        {assign var="valueDirect" value=$statistics[$indiceDirect]}
                    {else}
                        {assign var="valueDirect" value=0}
                    {/if}
                    {if isset($statistics[$indiceIndirect])}
                        {assign var="valueIndirect" value=$statistics[$indiceIndirect]}
                    {else}
                        {assign var="valueIndirect" value=0}
                    {/if}
                <tr>
                    <td class="left">{$sponsored.reference}</td>
                    <td class="left">{$sponsored.lastname|escape:'html':'UTF-8'} {$sponsored.firstname|escape:'html':'UTF-8'}</td>
                    <td class="center">{$sponsored.total_products_wt|intval} {l s=' DA'}</td>
                    <td class="total right">{$sponsored.date_add|date_format:'%d/%m/%Y'}</td>
                </tr>
                    <tr>
                        <td colspan="3" class="left">
                            <strong>{$sponsored.email|escape:'html':'UTF-8'}</strong> / <strong>{$sponsored.phone_mobile|escape:'html':'UTF-8'}</strong>
                        </td>
                        <td colspan="1" class="button_validate">
                            {if $sponsored.current_state == 27}
                                <button type="submit" class="btn btn-success validate_order_filleul" data-id_order="{$sponsored.id_order}">{l s='Valider la commande'}</button>
                            {else}
                                <button type="submit" class="btn btn-warning validate_order_filleul" disabled>{l s='Commande déjà valider'}</button>
                            {/if}
                        </td>
                    </tr>
                {/foreach}

<script type="application/javascript">
    $('button.validate_order_filleul').click(function () {
        $('.loading').show();
        $.ajax({
            type: 'POST',
            url: '{$link->getModuleLink('allinone_rewards', 'sponsorship')}',
            async: false,
            dataType: 'json',
            data: {
                action: 'ambassadricesValide',
                ajax: true,
                id_order: $(this).data('id_order')
            },
            success: function(jsonData) {

                $('.loading').hide();
                if (jsonData.Success === "OK") {
                    $('#msg').show();
                    $('#msg').html('<i class="icon-ok"></i> <p>{l s='Commande validée.'}</p>').fadeIn('slow');
                    $('#msg').delay(5000).fadeOut('slow');
                    console.log($(this));
                }
            }
        });
    });
</script>

这个过程很简单。当您单击“验证”时,按钮会在“已经验证”时成功通过,而不会重新加载页面。

由于

0 个答案:

没有答案