Pergunta

Hi everyone i am new here and this is my first question.

I have a problem with some JS code in IE 11.

this is the problem:

 <script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#jqueryFuction').load('ping?sessioneWeb=${requestScope.sessioneWeb}').fadeIn("slow");
}, 1000); // refresh every 10000 milliseconds

</script>
<div id="jqueryFuction">

 </div>

this code send a request in my server that control if there is some JS code to push on the client.

in my server (i use Spring MVC) i write that code:

@RequestMapping(value = "/ping")
    @ResponseBody public String ping(HttpServletRequest request, HttpServletResponse response,@ModelAttribute("sessioneWeb")String sessioneWeb,@ModelAttribute("item")ClientWom3Form item)
    {
        UserContainer userContainer = (UserContainer) request.getSession().getAttribute(sessioneWeb);

        if(userContainer != null && Util.isNotNull(userContainer.getFuctionReadyJQ()))
        {
            String valore = "<script type=\"text/javascript\">"+userContainer.getFuctionReadyJQ()+"</script>";
            userContainer.setFuctionReadyJQ("");
            return valore;
        }
        else
            return "";
    }

with this code i can push the JS code in my

this code works fine in Chrome and FF, but in IE doesn't. i can't reach the server and i don't know why.

I see that the browser pass to the load every second but it doesn't reach the server and the console doesn't show any error.

I use jquery-1.10.2.min.js

can anyone helps me please?

thank you to all for attention and help

Foi útil?

Solução

IE is famous for caching requests like this. I'd suggest you add a unique argument to the URL to bust the caching.

<script type="text/javascript">
var auto_refresh = setInterval(function () {
    var now = new Date().getTime();
    $('#jqueryFuction').load('ping?sessioneWeb=${requestScope.sessioneWeb}&timestamp=' + now).fadeIn("slow");
}, 1000); // refresh every 10000 milliseconds

</script>

Also, the fadeIn() won't work unless #jqueryFuction is set to hidden before you do the .load().

I'd also argue that you really don't want to be doing an ajax call every second. Some ajax calls will take more than a second to even process and if you have a lot of viewers, this will bring your server to its knees. Think about a much longer time interval or a more efficient way to let your server tell you when there's something new (like websockets).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top