this.toPaddedString不是函数原型

时间:2013-05-09 06:23:30

标签: jquery ajax magento prototype

我在使用jQuery和prototype时遇到此错误。我在magento中为运费计算模块编写了自定义javascript,我无法在firebug控制台中解决此错误。任何知道解决这个问题的人,请写在这里。

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 );

由于

1 个答案:

答案 0 :(得分:1)

很抱歉迟到的回复,但我得到了同样的错误,但情况略有不同。我正在进行ajax调用时,我的数据格式不正确。我最终做了$ .ajax(...,data:{key:value},...)并且它最终工作了。

这是当我搜索错误时出现的最高职位,所以我认为我应该分享其他人处于同样的情况。