To refresh page in JavaScript, we use location.reload()
function.
It is used to reload the current document. But if the origin of the script calling location.reload() differs from the origin of the page that owns the Location object, the reload may be blocked and a SECURITY_ERROR DOMException thrown.
In the following example, I tried sending data to a PHP file via AJAX. If the total items are too many, I prefer refreshing the page rather than modifying only certain HTML DOM.
jQuery('.btn-save').on('click', function(){ var keyword = jQuery('.keyword').val(); jQuery.ajax({ url: "action.php", type: "GET", data: 'keyword=' + keyword, success: function (response) { if(response.count > 100){ location.reload(); } else { //loop response.items } }, error: function(jqXHR, textStatus, errorThrown) { console.log(textStatus, errorThrown); } }); });