jquery - global variable in javascript is always empty and never updated -
i've got 1 partial view , when click link in partial view add hashset url , make ajax request , update view;( i'm trying achieve when click button load again previous partial view). problem on document ready check each second if there change in hashet - , seems each time check variable recenthash
in chechash finction empty. may reason.
@model mvcbeaweb.groupmenu <div class="lc-container-contentmenu"> foreach (mvcbeadal.webservicebeamenu item in model.menuleft) { @html.actionlink(@item.specialword, "importshow", new { menuid = @item.id, articlegroupid = @item.articlegroupid }) } </div> <script> var recenthash = ''; function hashchange() { var page = location.hash.slice(1); if (page != "") { jquery.ajax({ url: page }).done(function (data) { $("#importpartupdate").html(data); }) } } function checkhash() { var hash = location.hash; if (hash) { if (hash == recenthash) { return; } recenthash = hash; hashchange(); } } $(function () { $('.ajaxlinks a').click(function (e) { location.hash = $(this).attr('href') return false; }) setinterval(checkhash, 1000); }); </script>
this issue scoping.
var recenthash
, recenthash
(defined on window.hash) scoped differently.
http://ryanmorr.com/understanding-scope-and-context-in-javascript/
Comments
Post a Comment