Refreshing jstree after successful rename event (maybe WCF and or caching problem?)

自作多情 提交于 2019-12-13 03:36:54

问题


I have a jstree that loads it's data from a DB through a WCF service using JSON.

I managed to get jstree's rename context menu item to "work", meaning: I bound an ajax call to the jstree rename event, so when the user renames a node, it tells a WCF method to update the database (to "save" the new name).

Problem: If I go to another page and then come back later, the node has reverted to the old name!

It looks like there is some kind of caching going on, either in jstree or the browser, or WCF, and the tree isn't being refreshed somehow.

The data is coming from a database via a WCF service method over JSON. When you first visit the page, the data is loaded. But when you come back to the page, it isn't: the breakpoint in the server-side load method is never hit. It seems likely to me that either:

  • jstree has cached the data and doesn't try to load it again (but why doesn't it stay renamed?)

OR

  • jstree asks the service, but WCF just gives the same data again from a cache rather than actually running the service method.

OR

  • The browser is caching the request and giving the same result back to jstree without calling the WCF method.

Any ideas? How can I check this?


回答1:


Because you not sure whether you have caching problem I suggest you to include in the WCF method which you call from jstree the following line (for example as the first line in the method body):

WebOperationContext.Current.OutgoingResponse.Headers.Set (
    HttpResponseHeader.CacheControl,
    "max-age=0");

It will follow to cache revalidation. So the web browser or a proxy, which probably are also used, will not not use the cached vesrsion of data without revalidation (calling the same WCF method) on the server. You can also consider to use other cache-control options.



来源:https://stackoverflow.com/questions/4435398/refreshing-jstree-after-successful-rename-event-maybe-wcf-and-or-caching-proble

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!