我对成功触发事件有疑问 ajax。
我需要在<a>
中调用AJAX后触发点击[success: function(res){}]
标记,但出于某种原因,它不想工作。
<script type="text/javascript">
$j = jQuery.noConflict();
function popUpPaypal(){
$j.ajax({
url: '<?= Mage::getBaseUrl()?>xpayment/index',
type: 'POST',
data: {},
success: function(res){
$j('#payPalRedirect').attr('href','https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey='+res+'&expType=mini');
//the link are change but i want call click event of $j("payPalRedirect");
}
});
}
</script>
答案 0 :(得分:0)
您是否在此案例中使用了触发事件。
$ j = jQuery.noConflict();
function popUpPaypal(){
$j.ajax({<br/>
url: '<?= Mage::getBaseUrl()?>xpayment/index',
type: 'POST',
data: {},
success: function(res){
$j('#payPalRedirect').attr('href','https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey='+res+'&expType=mini');
**$('#payPalRedirect').trigger('click');**
}
});
}
答案 1 :(得分:0)
您刚刚更改了锚标记的网址 你必须触发它的点击
请参阅Trigger
<script type="text/javascript">
$j = jQuery.noConflict();
function popUpPaypal(){
$j.ajax({
url: '<?= Mage::getBaseUrl()?>xpayment/index',
type: 'POST',
data: {},
success: function(res){
$j('#payPalRedirect').attr('href','https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey='+res+'&expType=mini');
//the link are change but i want call click event of $j("payPalRedirect");
//code for triggering click
$j('#payPalRedirect').trigger('click');
}
});
}
答案 2 :(得分:0)
如果点击无效,您可以使用基本的JavaScript
window.location = 'https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey='+res+'&expType=mini';