2013-02-02 37 views
0

我需要在Javascript函數中包含對PayPal的調用。我希望致電PayPal 之前執行myStep1myStep2使用單獨的Javascript函數提交隱藏的PayPal表單

下面是函數:

function() {  
    // need call to PayPal here, before myStep1 and myStep2 
    $.when.apply(undefined, myStep1()).done(function() { 
    $.ajax({ 
     url: sURL + "myController/myStep2", 
     success: function() { 
       $.msg("Success Message", live:10000 
       }); 
      }, 
     error: function(){ 
       $.msg("Error Message", live:10000 
       }); 
      } 
     }); 
    }); 
}; 

這裏是PayPal的形式必須是無形的,通過上面的Javascript功能以某種方式提交:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> 
    <input type="hidden" name="cmd" value="_s-xclick"> 
    <input type="hidden" name="hosted_button_id" value="123456789"> 
    <input type="image" 
     src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_SM.gif" 
     border="0" name="submit" 
     alt="PayPal - The safer, easier way to pay online!"> 
    <img alt="" border="0" 
     src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" 
     height="1"> 
</form> 

就如何最好地實現任何想法這個PayPal表單提交到Javascript函數中?我想我可能會試圖做的是模擬點擊貝寶按鈕。謝謝。

+0

此插件可能有幫助:http://samdeering.com/jquerypaypalbuyitnow/ – mccannf

回答

1

貝寶按鈕是iFrame項目。

首先,您不能通過跨瀏覽器成功的JS函數調用提交。其次,你不能影響iFrame的JS行爲。您只能影響包含iFrame的頁面的操作。這是iFrames的本質。

您正在有效地嘗試通過客戶端腳本控制另一個站點上另一個頁面的操作。

1

試試這個嗎?

// This will disable the normal PayPal submit 
var buttn = $('input[name=submit]'); 
buttn.click(function(e) { 
    e.preventDefault(); 
}); 

function() {  
    // need call to PayPal here, before myStep1 and myStep2 
    buttn.closest('form').submit(); 
    $.when.apply(undefined, myStep1()).done(function() { 
    $.ajax({ 
     url: sURL + "myController/myStep2", 
     success: function() { 
       $.msg("Success Message", live:10000 
       }); 
      }, 
     error: function(){ 
       $.msg("Error Message", live:10000 
       }); 
      } 
     }); 
    }); 
};