Javascript 运行的Ajax公式在1行之后停止工作。
这很奇怪。包括第29行工程之前的所有代码。第29行之后的所有代码都不起作用。我在控制台上试了第30行和第31行,结果都成功了。我试着在第29行之前添加一行简单的代码,将背景改为红色,结果成功了。我把同一行放在第29行之后,但它不起作用Javascript 运行的Ajax公式在1行之后停止工作。,javascript,ajax,jquery,Javascript,Ajax,Jquery,这很奇怪。包括第29行工程之前的所有代码。第29行之后的所有代码都不起作用。我在控制台上试了第30行和第31行,结果都成功了。我试着在第29行之前添加一行简单的代码,将背景改为红色,结果成功了。我把同一行放在第29行之后,但它不起作用 $('#button-shipping-method').live('click', function() { $.ajax({ url: 'index.php?route=checkout/shipping_method/validate
$('#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);
}
});
});
$(“#按钮运送方法”).live('click',function(){
$.ajax({
url:'index.php?route=checkout/shipping\u method/validate',
键入:“post”,
数据:$('shipping method input[type='radio\']:选中,'shipping method textarea'),
数据类型:“json”,
beforeSend:function(){
$(“#按钮运送方法”).attr('disabled',true);
$(“#按钮装运方式”)。在(“”)之后;
},
完成:函数(){
$(“#按钮运送方法”).attr('disabled',false);
$('.wait').remove();
},
成功:函数(json){
$('.warning,.error').remove();
if(json['redirect']){
location=json['redirect'];
}else if(json['error']){
如果(json['error']['warning']){
$('#shipping method.checkout content').prepend(''+json['error']['warning']+'');
$('.warning').fadeIn('slow');
}
}否则{
$.ajax({
url:'index.php?route=checkout/payment_method',
数据类型:“html”,
成功:函数(html){
$('#payment method.checkout content').html(html);//第29行
$('#shipping method.checkout content').slideUp('slow');
$(“#付款方式.结帐内容”).slideDown('slow');
$(“#装运方法.签出标题a”).remove();
$(“#付款方式.签出标题a”).remove();
$(“#装运方法.签出标题”).append(“”);
},
错误:函数(xhr、ajaxOptions、thrownError){
警报(thrownError+“\r\n”+xhr.statusText+“\r\n”+xhr.responseText);
}
});
}
},
错误:函数(xhr、ajaxOptions、thrownError){
警报(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
的警报,则该元素存在;如果为零,则该元素不存在
让我们知道。您是在说“滑动”和“滑动下降”之间吗?控制台中有错误吗?是的,滑动下降和滑动下降不起作用。。。第29行之后的任何代码我猜都不会是选择器返回空对象,但是在没有看到html或不知道任何控制台错误的情况下,这是一种盲目的猜测。这可能是因为html返回触发了一个错误。您可以向我们展示ajax调用返回的html代码吗?也许它里面有一些javascript给出了这个“uncaughttypeerror”,然后将警报框放在第29行之前。如果弹出那个,那么问题是第29行。那就按照我的建议去做吧。基本上,每行前面的alert()框将告诉您哪一行有问题,然后使用.length方法将告诉您此时DOM中是否存在该控件。您还可以使用Firebug或Chrome开发工具(Ctrl+Shift+i,然后查看元素选项卡)来检查DOM并亲自查看。希望它像打字一样简单。。。