简体   繁体   中英

Update the value of an element in wordpress without having to refresh the whole page

I have a counter in wordpress that I want to update without refreshing the whole page. This counter takes the value of a shortcode, could it be called every x time without having to refresh the page?

Please check the below code. It's very useful to you. You can use it by making necessary changes.

 <script> setInterval(function(){ var d = document.getElementById("ctajax"); d.className += " loaderstart"; $.ajax({ url: 'your_base_url', type: 'POST', data: {perameter1: 'value1', perameter2: 'value2'}, error: function() { alert('Something is wrong'); }, success: function(data) { $("#your_main_div_id").html(data); setTimeout(function () { var element = document.getElementById("ctajax"); element.classList.remove("loaderstart"); }, 3000); // in milliseconds alert("successfully"); } }); }, 600000); </script>

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM