2012-02-20 3 views
0

2番目のコールが最初のコールが成功した場合のみアクティブになるように、Magentoのいくつかのコードを修正しようとしています。具体的には、チェックアウト時に課金ページに追加のアドレス検証コードを挿入しようとしているため、Magentoの有効化+フォームの投稿(AJAX経由)は、住所が有効な郵便番号として有効である場合にのみ発生します。Magento/JavaScript/Prototype:ネストされたAJAXコールのネームスペースに関する情報が必要

私の問題は、いくつかの名前空間の問題にぶつかっている内部呼び出しで特定の関数を参照しようとしたことに由来します。コード例:彼らは、ネストされた呼び出しにしていたら、このようなthis.formをしてthis.onCompleteなど

var Billing = Class.create(); 
Billing.prototype = { 
initialize: function(form, addressUrl, saveUrl){ 
    this.form = form; 
    if ($(this.form)) { 
     $(this.form).observe('submit', function(event){this.save();Event.stop(event);}.bind(this)); 
    } 
    this.addressUrl = addressUrl; 
    this.saveUrl = saveUrl; 
    this.onAddressLoad = this.fillForm.bindAsEventListener(this); 
    this.onSave = this.nextStep.bindAsEventListener(this); 
    this.onComplete = this.resetLoadWaiting.bindAsEventListener(this); 
}, 

save: function() { 
    //(initialize things for first call, e.g., URL to use): 
    var addressRequest = new Ajax.Request(url, 
     { 
      method: 'get', 
      onSuccess: function(response) { 
       // (do some things with the results...) 

       // (initialize things for second call, which was 
       // the stock Magento AJAX call to validate form fields 
       // and post the results to another Web page...) 

       var request = new Ajax.Request(
        this.saveUrl, // no longer in scope 
        { 
         asynchronous: true, 
         method: 'post', 
         onComplete: this.onComplete, // also no longer in scope 
         onSuccess: this.onSave, // also no longer in scope 
         onFailure: checkout.ajaxFailure.bind(checkout), // "checkout" is a distinct object and remains in scope 
         parameters: Form.serialize(this.form) // this.form no longer in scope 
        } 
      ); 
      } 
     } 
    }, 

    fillForm: function(transport) { ... }, 

    nextStep: function(transport) { ... }, 

    resetLoadWaiting: function(transport) { ... }, 

オリジナルの「this.xxx」参照がもはや範囲です。どのネストされた深さでもそれらを正しく参照する方法を知りたいと思います(私がここでもやりたいことがある他のAJAXコールがいくつかあります)。どんな提案も大歓迎です!

答えて

1

は、これがうまく働いていた

onSuccess: function(response) { 
... 
}.bind(this); 
+0

を試してみてください。ありがとう! –

関連する問題