【问题标题】:PHP/Ajax Default valuesPHP/Ajax 默认值
【发布时间】:2014-05-11 02:55:44
【问题描述】:

我放弃了。有人可以帮我看看吗。目前,我有一个验证用户付款地址的页面,然后当他们点击继续验证送货地址。它突出显示默认地址。我希望它发布付款地址的默认值并在页面加载时跳转到跳过地址。

所以我在这里有它,当您单击继续按钮时,它会提交帐单地址并移动到送货地址。

// Payment Address  
$('#button-payment-address').live('click', function() {
    $.ajax({
        url: 'index.php?route=checkout/payment_address/validate',
        type: 'post',
        data: $('#payment-address input[type=\'text\'], #payment-address input[type=\'password\'], #payment-address input[type=\'checkbox\']:checked, #payment-address input[type=\'radio\']:checked, #payment-address input[type=\'hidden\'], #payment-address select'),
        dataType: 'json',
        beforeSend: function() {
            $('#button-payment-address').attr('disabled', true);
            $('#button-payment-address').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
        },  
        complete: function() {
            $('#button-payment-address').attr('disabled', false);
            $('.wait').remove();
        },          
        success: function(json) {
            $('.warning, .error').remove();

            if (json['redirect']) {
                location = json['redirect'];
            } else if (json['error']) {
                if (json['error']['warning']) {
                    $('#payment-address .checkout-content').prepend('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');

                    $('.warning').fadeIn('slow');
                }

                if (json['error']['firstname']) {
                    $('#payment-address input[name=\'firstname\']').after('<span class="error">' + json['error']['firstname'] + '</span>');
                }

                if (json['error']['lastname']) {
                    $('#payment-address input[name=\'lastname\']').after('<span class="error">' + json['error']['lastname'] + '</span>');
                }   

                if (json['error']['telephone']) {
                    $('#payment-address input[name=\'telephone\']').after('<span class="error">' + json['error']['telephone'] + '</span>');
                }       

                if (json['error']['company_id']) {
                    $('#payment-address input[name=\'company_id\']').after('<span class="error">' + json['error']['company_id'] + '</span>');
                }   

                if (json['error']['tax_id']) {
                    $('#payment-address input[name=\'tax_id\']').after('<span class="error">' + json['error']['tax_id'] + '</span>');
                }   

                if (json['error']['address_1']) {
                    $('#payment-address input[name=\'address_1\']').after('<span class="error">' + json['error']['address_1'] + '</span>');
                }   

                if (json['error']['city']) {
                    $('#payment-address input[name=\'city\']').after('<span class="error">' + json['error']['city'] + '</span>');
                }   

                if (json['error']['postcode']) {
                    $('#payment-address input[name=\'postcode\']').after('<span class="error">' + json['error']['postcode'] + '</span>');
                }   

                if (json['error']['country']) {
                    $('#payment-address select[name=\'country_id\']').after('<span class="error">' + json['error']['country'] + '</span>');
                }   

                if (json['error']['zone']) {
                    $('#payment-address select[name=\'zone_id\']').after('<span class="error">' + json['error']['zone'] + '</span>');
                }
            } else {
                <?php if ($shipping_required) { ?>
                $.ajax({
                    url: 'index.php?route=checkout/shipping_address',
                    dataType: 'html',
                    success: function(html) {
                        $('#shipping-address .checkout-content').html(html);

                        $('#payment-address .checkout-content').slideUp('slow');

                        $('#shipping-address .checkout-content').slideDown('slow');

                        $('#payment-address .checkout-heading a').remove();
                        $('#shipping-address .checkout-heading a').remove();
                        $('#shipping-method .checkout-heading a').remove();
                        $('#payment-method .checkout-heading a').remove();

                        $('#payment-address .checkout-heading').append('<a><?php echo $text_modify; ?></a>');   
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
                <?php } else { ?>
                $.ajax({
                    url: 'index.php?route=checkout/payment_method',
                    dataType: 'html',
                    success: function(html) {
                        $('#payment-method .checkout-content').html(html);

                        $('#payment-address .checkout-content').slideUp('slow');

                        $('#payment-method .checkout-content').slideDown('slow');

                        $('#payment-address .checkout-heading a').remove();
                        $('#payment-method .checkout-heading a').remove();

                        $('#payment-address .checkout-heading').append('<a><?php echo $text_modify; ?></a>');   
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                }); 
                <?php } ?>

                $.ajax({
                    url: 'index.php?route=checkout/payment_address',
                    dataType: 'html',
                    success: function(html) {
                        $('#payment-address .checkout-content').html(html);
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });             
            }     
        },
        error: function(xhr, ajaxOptions, thrownError) {
            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
    }); 
});

我认为它就像替换一样简单

$('#button-payment-address').live('click', function() {

$(document).ready(function() {

但这不起作用。最终所有部分都将加载默认值,我将只有一个按钮来提交所有表单,但显然,如果我什至不能让一个部分接受默认值,我就无法继续前进。

【问题讨论】:

  • 不替换...$(document).ready(function() {$('#button-payment-address').live('click', function() {}); } );
  • 这似乎没有得到默认值。它仍在等待我点击按钮支付地址按钮,我正在努力消除对它的需求

标签: php ajax default-value


【解决方案1】:

如果您能澄清其中的哪一部分不起作用,那将会很有帮助。但在不知道的情况下......如果您使用的是 1.7 或更高版本的 jQuery,则使用 .on() 可能会起作用,因为此时不推荐使用 .live()

【讨论】:

  • 好吧,如果我只是将其更改为 $(document).ready(function() { 帐单地址确实会向上滑动,并且会显示送货地址,但是我会继续执行其余步骤,到最后,它说没有选择付款地址并将我扔回顶部。它永远不会获得付款地址。但同样,使用相同的代码,但使用 $('#button-payment-address')。 live('click', function() { 它运行良好。我使用的是 1.7.1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-25
  • 1970-01-01
  • 2011-06-17
  • 2011-08-26
  • 2012-05-05
相关资源
最近更新 更多