Wednesday, September 18, 2019

JavaScript: Reload or refresh the current URL


This blog will discuss how to refresh or reload the current window document or current page in JavaScript by using calling Location.Reload() method

Basically location object contains the information about the current URL and we can easily access location object through the window.location property.

Here is an JavaScript example to reload the current URL by using Location.Reload() method.

         $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (result) {
                    if (result == "Record was saved successfully") { 
                        location.reload();
                    }
                    else {
                        $('#error).html(result);
                    }
                }

In above example, we are posting form by using Ajax Post, on success event, if record was save successfully, we are reloading the current URL.

There is optional parameter for Reload () method, we can specify the optional parameter value to true to enforce to reload () method to reload current page from server instead from cache.

location.reload(true);


No comments:

SQL Server - Identify unused indexes

 In this blog, we learn about the index usage information (SYS.DM_DB_INDEX_USAGE_STATS) and analyze the index usage data (USER_SEEKS, USER_S...