3

jQuery とプロトタイプを一緒に使用すると、このエラーが発生します。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 );

ありがとう

4

1 に答える 1

1

返信が遅くなり申し訳ありませんが、同じエラーが発生しましたが、状況が少し異なります。ajax 呼び出しを行っているときに、データが正しくフォーマットされていませんでした。私は $.ajax(..., data: {key:value},...) をやってしまい、うまくいきました。

これは、エラーをグーグルで検索したときに表示されたトップの投稿だったので、他の誰かが同じ状況にある場合に備えて共有する必要があると考えました.

于 2015-07-31T00:41:08.870 に答える