Javascript从ajax响应运行一次

时间:2016-01-07 07:21:11

标签: jquery jquery-mobile opencart2.x

我在点击checkoutbutton时打开购物车结帐页面数据,使用html和javascript代码检索结帐响应,javascript代码只运行一次。如果我在没有刷新的情况下再次打开结帐页面或只是单击结帐按钮,则响应代码无法再次运行 注意:ajax响应脚本中没有任何语法错误

抱歉我的英文不好

我正在检索数据的地方

function createnewPage_loadURL(createpageparam){
    var loadpageurl = '';
    if(typeof createpageparam.loadpageurl!=='undefined'){
        loadpageurl = domainurl+'index.php?route='+createpageparam.loadpageurl+'&therandparam='+unique_chrs('',10)
    }
    $.ajax({
        type:"GET",
        url:loadpageurl
    }).success(function(pageloadresponse){
        $(target_sel_fill_loaddata).html(pageloadresponse);
    });
}

响应示例

<script type="text/javascript">
    alert('THIS ALERT SHOWING ONCE ONLY');

    $(document).on('change', 'input[name=\'account\']', function() {
        if ($('#collapse-payment-address').parent().find('.panel-heading .panel-title > *').is('a')) {
            if (this.value == 'register') {
                $('#collapse-payment-address').parent().find('.panel-heading .panel-title').html('<a href="#collapse-payment-address" data-toggle="collapse" data-parent="#accordion" class="accordion-toggle"><?php echo $text_checkout_account; ?> <i class="fa fa-caret-down"></i></a>');
            } else {
                $('#collapse-payment-address').parent().find('.panel-heading .panel-title').html('<a href="#collapse-payment-address" data-toggle="collapse" data-parent="#accordion" class="accordion-toggle"><?php echo $text_checkout_payment_address; ?> <i class="fa fa-caret-down"></i></a>');
            }
        } else {
            if (this.value == 'register') {
                $('#collapse-payment-address').parent().find('.panel-heading .panel-title').html('<?php echo $text_checkout_account; ?>');
            } else {
                $('#collapse-payment-address').parent().find('.panel-heading .panel-title').html('<?php echo $text_checkout_payment_address; ?>');
            }
        }
    });
<?php  if (!$logged) { ?>

            $.ajax({
                url: domainurl+'index.php?route=mobile/checkout/login',
                dataType: 'html',
                success: function(html) {
                    $('#collapse-checkout-option .panel-body').html(html);

                    $('#collapse-checkout-option').parent().find('.panel-heading .panel-title').html('<a href="#collapse-checkout-option" data-toggle="collapse" data-parent="#accordion" class="accordion-toggle"><?php echo $text_checkout_option; ?> <i class="fa fa-caret-down"></i></a>');

                    $('a[href=\'#collapse-checkout-option\']').trigger('click');
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                }
            });

    <?php } else { ?>
            alert('mobile/checkout/payment_address__LINE-121');
            $.ajax({
                url: domainurl+'index.php?route=mobile/checkout/payment_address',
                dataType: 'html',
                success: function(html) {
                    $('#collapse-payment-address .panel-body').html(html);

                    $('#collapse-payment-address').parent().find('.panel-heading .panel-title').html('<a href="#collapse-payment-address" data-toggle="collapse" data-parent="#accordion" class="accordion-toggle"><?php echo $text_checkout_payment_address; ?> <i class="fa fa-caret-down"></i></a>');

                    $('a[href=\'#collapse-payment-address\']').trigger('click');
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                }
            });

    <?php } ?>
</script>

0 个答案:

没有答案