2017-05-15 44 views
0

我想的.html前添加加載文本()負載完全在我的網頁HTML()

這裏之前加載文本添加到JavaScript是我的代碼

$.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

爲了有更好的控制您的阿賈克斯呼叫使用以下阿賈克斯風格:

$.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 
    } 
}); 
+0

加載效果不可能在我自己的代碼? –

+0

@MehranPourjenabi您可以在div中加載新的內容,然後用新加載的內容替換所有內容,但上面給出的方法要好得多。你也可以通過查詢以下答案http://stackoverflow.com/questions/2257975/using-beforesend-and-complete-with-post –

+0

@MehranPourjenabi你的問題已解決? –