0

I try to change the button of a painting at the moment of success. Here is what my code looks like:

my array:

enter image description here

template:

{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>

The process is simple. When you click on "Validate" the button passes at the time of success in "Already validate" without reloading the page.

Thanks

  • And what is happening, not happening? Expected result vs actual result? You could remove all templating if this is a jQuery question. Then just post relevant HTML, JS and CSS – mplungjan Apr 17 '18 at 08:17
  • I would like to modify the button only on the button that I click. That's the problem I have –  Apr 17 '18 at 08:19

0 Answers0