在html()之前向javascript添加加载文本

时间:2017-05-15 11:05:51

标签: javascript

我想在.html()加载完成之前在我的页面

中添加加载文本

这是我的代码

  $.post("<?php echo get_template_directory_uri(); ?>/template-parts/live.php", { couplername:couplername, couplercount:couplercount, couplerlathing:couplerlathing, couplerwhois:couplerwhois, couplerdetailsname:couplerdetailsname, couplerdetailsid:couplerdetailsid, couplerdetailsnumber:couplerdetailsnumber },

  function(data) {
    $("#order_price").html(data);
  });

1 个答案:

答案 0 :(得分:1)

为了更好地控制你的ajax调用,请使用以下ajax样式:

$.ajax({
    url: 'http://example.com',
    method: 'POST',
    data : {
        someKey : "SOME_VAL",
        anotherKey : "ANOTHE_VAL"
    },
    beforeSend:function(){
        //HERE YOU CAN SHOW LOADING ETC.
    },
    success: function (response) {
        //HERE YOU CAN GET THE RESPONSE of AJAX
    },
    error: function (e) {
        //HERE YOU CAN HANDLE SITUATIONS OF ERROR
    },
    complete : function(){
        //HERE YOU CAN REMOVE THE LOADING
    } 
});