Ajax call function after success

回眸只為那壹抹淺笑 提交于 2019-12-01 03:42:30

Use hulabula instead of hulabula() or pass the function directly to the ajax options:

1.

$.ajax({
    type: "GET",
    //Url to the XML-file
    url: "data_flash_0303.xml",
    dataType: "xml",
    success: hulabula
});

2.

$.ajax({
    type: "GET",
    //Url to the XML-file
    url: "data_flash_0303.xml",
    dataType: "xml",
    success: function(xml) { /* ... */ }
});

Use $.when

function hulabula(xml) {
            $(xml).find('top').each(function() {
                var headline = $(this).find('headline1').text();
                var headlineTag = $(this).find('headline2').text();

                $(".wunMobile h2 strong").text(headline + " ");
                $(".wunMobile h2 span").text(headlineTag);
            });
}


var ajaxCall  = $.ajax({
        type: "GET",
        //Url to the XML-file
        url: "data_flash_0303.xml",
        dataType: "xml"
    });

//Use deferred objects

$.when(ajaxCall)
 .then(function(xml) { hulabula(xml); });
Balsa

You can do it like this:

   $.post( "user/get-ups-rates", { cart_id: cart_id, product_id: product_id, service_id:service_id })
    .done(function( data ) {
         el.parent().find('.upsResult').html('UPS Shipping Rate Is $'+data.rate);
    })
    .fail(function(data) {
          el.parent().find('.upsResult').html('<p style="color:red">UPS Service Error Occured. </p>');
     })
     .complete(function (data) {   
         setShippingOptions(cart_id,product_id,service_id,data.rate);
    });

Just call the function in 'complete' not in 'done' or 'success'

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!