"!tagged" - Cached object in console?





symfony log (2)


Use console.dir(obj) for objects not console.log(obj), you are getting a string of the object by doing that so updating it will still work in your code but not show in the console. Strings are immutable, so no property update wil show in your console. Tip: Use watch expressions in chrome debugger.

I'll start with the problem :

  1. I'm changing the content of an object literal. (changing the properties values)
  2. The Firebug console (at first clicks) shows the correct values.
  3. But after a while, it get stuck on a specific value and stop from changing.

(notice : the stringify representation of the object - Always shows the correct values)

And here are the Details:

  1. I select a street in the textbox (it should set the StreetText value in the object)

  2. I look at the console (wide line) and press the last line , looking at the street text.

At first it's OK. In the second try, after I choose another street, it stays on the old value.

However, when I press refresh (on the object), it shows me the correct street name.

What is going on here?

My object is a regular object literal :

  var obj =
            {
                getData: function ()
                {

                    obj.CountryId = $(".ddlCountry").val() || "";
                    obj.CountryText = $(".ddlCountry  :selected").text() || "";
                    obj.StateId = $(".ddlState:visible").val() || "";
                    obj.StateText = $(".ddlState:visible  :selected").text() || "";
                    obj.CityId = $(".hfDataIdCity").val() || "";
                    obj.CityText = $(".hfDataTextCity").val() || "";
                    obj.StreetId = $(".hfDataIdStreet").val() || "";
                    obj.StreetText = $(".hfDataTextStreet").val() || "";
                }
        }

and the display on the console is made by onclicking the button :

 obj.getData();
 console.log(obj);

Why I'm not seeing the correct values ? ( only after refresh....)

p.s. : ff: 14.0.1
fb:1.10.6

and the cache is turned off




For those that use Struts 1, here is how I fixed the issue.

web.xml

<filter>
    <filter-name>SetCacheControl</filter-name>
    <filter-class>com.example.struts.filters.CacheControlFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>SetCacheControl</filter-name>
    <url-pattern>*.do</url-pattern>
    <http-method>POST</http-method>
</filter-mapping>

com.example.struts.filters.CacheControlFilter.js

package com.example.struts.filters;

import java.io.IOException;
import java.util.Date;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;

public class CacheControlFilter implements Filter {

        public void doFilter(ServletRequest request, ServletResponse response,
                     FilterChain chain) throws IOException, ServletException {

        HttpServletResponse resp = (HttpServletResponse) response;
        resp.setHeader("Expires", "Mon, 18 Jun 1973 18:00:00 GMT");
        resp.setHeader("Last-Modified", new Date().toString());
        resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
        resp.setHeader("Pragma", "no-cache");

        chain.doFilter(request, response);
    }

    public void init(FilterConfig filterConfig) throws ServletException {
    }

    public void destroy() {
    }

}