简体   繁体   中英

Using jquery how to refresh the contents of .load()

Below is my code

 window.onload = function () {

        var startup = '@ViewBag.site';

        var url = '@Url.Action("data_type_partial", "HistorySite", new { sitename = "java_get"})'
        var url = url.replace("java_get", startup);

        $("#loader").load(url);
    };


    function change(val) {
        var url = '@Url.Action("data_type_partial", "HistorySite", new { sitename = "java_get"})'
        var url = url.replace("java_get", val);

        $("#loader").load(url);
      }

On windows startup I am using .load() to load a partial view into #loader div . After i click a button to call change() function,the #loader div should then change to the new .load(url) .The problem is that when i click on the button it doesn't change to the new .load() but stays the same

How can i do this?

Thanks

Probably the url that you're calling is cached before!

Check if it's where cached, replace this with your "change" function:

    function change(val) {
    var url = '@Url.Action("data_type_partial", "HistorySite", new { sitename = "java_get"})'
    var url = url.replace("java_get", val);

    $("#loader").load(url + '?noCache=' + (new Date).getTime() );
  }

This will prevent from cashing.

Hope this will help you.

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