2013-05-09 102 views
3

當我一起使用jQuery和原型時出現此錯誤。我爲magento中的運輸計算模塊編寫了自定義JavaScript,並且無法在螢幕控制檯中解決此錯誤。任何知道解決此問題的人都請寫在這裏。this.toPaddedString不是函數原型

TypeError: this.toPaddedString is not a function 
[Break On This Error] 

return this.toPaddedString(2, 16); 

這裏是JS iam使用但未對原型做任何改變,仍然從原型出現錯誤。

(function($) { 
     // we can now rely on $ within the safety of our "bodyguard" function 
     $(document).ready(function() { 

$('.s_code').change(function() { 
// remove all previous selections 
$('.option_all_box').attr('checked', false); 
$('.option_all').val('0'); 

// hide all divs 
$('.option_top').hide(); 

// show appropriate div & select first option 
if($(this).val() == 'A') 
{ 
$('.option_s').fadeIn(); 
$('.s_first').attr('checked', true); 
} 
else if ($(this).val() == 'B') 
{ 
$('.option_p').fadeIn(); 
$('.p_first').attr('checked', true); 
} 

}); 

$('#frm_calculate').change(function() { 
// ajaxify the calculate 
// submit the form 
$('#totalship').html('Please wait, Recalculating...'); 
formdata2 = $("form #frm_calculate").serialize(); 

var posting = $.post('calculate.php', formdata2, 'json'); 
posting.done(function(data) { 

//alert(data); 
if(data.error) 
{ 
//$('#totalship').html("Error!"); 
    if(data.error.errorMessage == 'Please enter a valid amount.') 
    { 
    $('#totalship').html('Please enter a valid amount for extra cover (greater than zero)'); 
    } 
    else 
    { 
    $('#totalship').html(data.error.errorMessage); 
    } 
} 
else 
{ 
var result = data.postage_result; 
    thisqty = <?php echo $qtyArray[$i];?> ; 
str = result.service + '<br>' + result.delivery_time + '<br>' + result.total_cost*thisqty; 

// loop over the cost breakdown 
//alert($(result.costs.cost).size()); 
listsize = $(result.costs.cost).size(); 

str = str + "<table width='100%'>"; 
if (listsize > 1) 
{ 
$.each(result.costs.cost, function(key,value) { 
str = str +'<tr><td width="50%">'+ value.item + '</td><td width="50%" style="text-align: right;">$' + value.cost*thisqty + '</td></tr>'; 
}); 
} 

else if (listsize == 1) 
{ 
value = result.costs.cost; 
str = str + '<tr><td width="50%">'+value.item + '</td><td width="50%" style="text-align: right;">$' + value.cost*thisqty + '</td></tr>'; 

} 
//Get variable from javascript back into this file's PHP code 
var sendtoget1 = result.total_cost; 
var sendtoget = sendtoget1; //*thisqty 
var posting2 = $.post('sendtoget.php', sendtoget , 'text'); 
posting2.done(function(data) { 
//alert(data); 
}); 

str = str + "</table>"; 

$('#totalship').html(str); 
$('#totalship').fadeIn(); 

} 


}); 
}); 

}); 
    }) (jQuery); 

感謝

+0

這個任何人嗎? – 2013-05-09 12:15:31

+0

抱歉,對於遲到的回覆 - 這個錯誤來自'toColorPart()'方法中的數字原型的擴展(用於將RGB顏色轉換爲十六進制顏色)。你似乎沒有在提供的JavaScript中使用任何類型的東西。你能追溯回棧看看發生錯誤的電話嗎? – 2013-05-12 17:15:25

+0

我沒有看到你在第二組JS中使用'.toPaddedString'函數的位置。你能爲你的問題添加更多的上下文嗎?這實際上無法解決問題。 – 2013-08-09 11:57:03

回答

1

很抱歉這麼晚纔回復,但我得到了同樣的錯誤,但在一個稍微不同的情況。我在進行ajax調用時數據格式不正確。我最終做了$ .ajax(...,data:{key:value},...),並且它結束了工作。

這是當我搜索錯誤時出現的頂級帖子,所以我想我應該分享別人是在相同的情況。