Ajax公式运行在1行之后停止工作
Ajax formula runs stops working after 1 line.
这很奇怪。包括第29行之前的所有代码都有效。第29行之后的所有代码都不起作用。我在控制台上试了试第30行和第31行,它们都起作用了。我尝试添加一行简单的代码,在第29行之前将背景更改为红色,结果成功了。我把同一行放在第29行之后,结果没用。
$('#button-shipping-method').live('click', function() {
$.ajax({
url: 'index.php?route=checkout/shipping_method/validate',
type: 'post',
data: $('#shipping-method input[type=''radio'']:checked, #shipping-method textarea'),
dataType: 'json',
beforeSend: function() {
$('#button-shipping-method').attr('disabled', true);
$('#button-shipping-method').after('<span class="wait"> <img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#button-shipping-method').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']) {
$('#shipping-method .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');
}
} else {
$.ajax({
url: 'index.php?route=checkout/payment_method',
dataType: 'html',
success: function(html) {
$('#payment-method .checkout-content').html(html); // LINE 29
$('#shipping-method .checkout-content').slideUp('slow');
$('#payment-method .checkout-content').slideDown('slow');
$('#shipping-method .checkout-heading a').remove();
$('#payment-method .checkout-heading a').remove();
$('#shipping-method .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
},
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);
}
});
});
看起来DOM中不存在带有id="shipping-method"
(在第30行引用)的HTML元素。
试试这个测试——在第30行插入:
alert('Line 30');
var test = $('#shipping-method').length;
alert(test);
alert('Line 33');
如果您收到1
警报,则该元素存在;如果为零,则该元素不存在。
让我们知道。
相关文章:
- 基于类的单击事件在10行之后不响应-数据表
- 如果字段在几行空行之后包含前几个字符,则验证描述字段长度
- 文本在jQuery中仅位于第一行之后的行的中心
- 在每行之后淡入
- 如何在表单中的每个输入/新行之后添加
标签 - Node.js:在文本文件中的特定行之后插入一行
- Ajax公式运行在1行之后停止工作
- 加载文件,并在特定行之后删除javascript/jquery中的所有剩余行
- 文本区域标签高亮显示应用于第一行之后的错误位置
- 在表的每行之后添加一行
- 在javascript的参数列表(第1行)之后缺少)
- 如何切断段落第一行之后的字符串
- <跨度>在第二行之后中断行
- 在javascript的每行之后暂停
- 在追加表的行之后无法获得dom元素
- 只有在重定向行之后调用alert()时,greasemmonkey发出的重定向才有效
- jQuery DataTable's的行索引在交换了两行之后不会更新(rowReordering插件)
- Javascript在具有特定id的行之后将行插入表中
- CSS在192行之后就不工作了
- 使用jquery在特定行之后添加一行,并使用滑动效果