【问题标题】:Backend is just called once后端只调用一次
【发布时间】:2012-12-16 19:14:17
【问题描述】:

我正在开发一个基于 Spring-MVC Web 的应用程序。 我使用 Freemarker 和 JQuery。 @Freemarker,我有以下 JQuery,它应该去后端两次:

 $(document).ready(function() {
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();
    $.getJSON('[@spring.url '/vacation/loadResourceVacation'/]', function (data) {
      $.getJSON('[@spring.url '/vacation/loadPublicVacations'/]', function (returnedPublicVacation) {....

这 2 个 java 方法是:

 @RequestMapping(value = "/loadResourceVacation", method = RequestMethod.GET)
  public
  @ResponseBody
  String loadResourceVacation(HttpServletResponse response) throws Exception {

    // Convert to JSON string.
    String json = new Gson().toJson(myObject);

    // Write JSON string.
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");

    return json;
  }


@RequestMapping(value = "/loadPublicVacations", method = RequestMethod.GET)
  public
  @ResponseBody
  String loadPublicVacations(HttpServletResponse response) throws Exception {

    // Convert to JSON string.
    String json = new Gson().toJson(someObj);

    // Write JSON string.
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");

    return json;
  }

@Google Chrom,它工作得非常好。 但是@ IE,它在我第一次加载页面时工作正常。 如果我再次尝试加载页面,这2个方法将不会被调用,并且会从第一次开始缓存。

如果我关闭会话并打开一个新会话,则将再次调用这 2 个方法。 任何帮助!

【问题讨论】:

    标签: javascript jquery internet-explorer spring-mvc freemarker


    【解决方案1】:

    jQuery documentation 说:

    缓存 - 布尔值

    默认值:true,对于 dataType 'script' 和 'jsonp' 为 false

    如果设置为 false,它将强制浏览器不缓存请求的页面。将缓存设置为 false 还会将查询字符串参数“_=[TIMESTAMP]”附加到 URL。

    【讨论】:

    • 正是... jQuery.ajaxSetup({ cache: false });
    猜你喜欢
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 2016-08-18
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多