jQuery .html()的回调函数? [英] Callback function for jQuery .html()?

查看:477
本文介绍了jQuery .html()的回调函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

$.ajax({
      type: 'GET',
      url: 'index.php?route=checkout/onepagecheckout/getpaypaldata',
      dataType: 'json',
      success: function(json) {
                              $('#pp_info').html(json['output']);
                              $('#payment').submit();
                              }
      });

ajax请求接收到一个json对象,其中包含html格式,如:

The ajax requests receives a json object containing a html form like :

<form id="payment" method="post" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" value="_cart" name="cmd">
<input type="hidden" value="1" name="upload">
<input type="hidden" value="test@yahoo.ca" name="business">
<input type="hidden" value="Sample Item Name" name="item_name_1">
<input type="hidden" value="TESTI-1" name="item_number_1">
<input type="hidden" value="104.98" name="amount_1">
<input type="hidden" value="1" name="quantity_1">
<input type="hidden" value="0" name="weight_1">
<input type="hidden" value="Type" name="on0_1">
<input type="hidden" value="As Shown" name="os0_1">
<input type="hidden" value="Delivery Date" name="on1_1">
<input type="hidden" value="Jun 23,2012" name="os1_1">
<input type="hidden" value="Comments" name="on3_1">
<input type="hidden" value="test message" name="os3_1">
</form>

,其中包含PayPal处理订单所需的信息.一切工作正常,但我相信有时在加载html内容完成jQuery .html函数之前先提交表单.

which contains the information that PayPal requires in order to process the order. Everything works fine except I believe sometimes the form gets submitted before the jQuery .html function is done with loading the html content.

.html是否有任何回调函数?还是我可以用来解决该问题的任何其他方法? PayPal数据以HTML表单的形式出现,我无法更改该部分,因此我只有一个选择,即以某种方式加载html内容并提交表单!

Is there any callback function for .html ? or any other method that I can use to solve the issue ? the PayPal data comes as a HTML form and I can't change that part, so I only have one option which is somehow load the html content and submit the form !

推荐答案

您可以尝试

success: function(json) {
    $('#pp_info').html(json['output']).promise().done(function(){
        $('#payment').submit();
    });
}

这篇关于jQuery .html()的回调函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆