1

when a user open a new dialog in my application. i am getting the dialog HTML and script who are responsible to handle that dialog. when i am opening the same dialog again.

seems like the browser is caching my javascript from the previous dialog. so for some cases i have scripts who are running twice.

example of i am doing :

var html = $.get('/somepage');
dialog.empty().append(html);
dialog.dialog("open");

how can i overcome that ?

here is an example that will help explain the problem

<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script id="myscript">var seachForMe = 1;</script>
<script>
    $(document).ready( function(){
        $("#clickme").click(function() {
            $("#centent").empty().append($("<span>some text </span>")).append($("#myscript").clone());
        });
    });
</script>
</head>
<body>
<div id="centent"></div>
<input type="button" id="clickme" value="click me again and again">
</body>
</html>

i am using clone, since it will be a new script returning from the server i am empty the content div but still the script is in the browser .

1 Answer 1

2

This should do the trick:

   var html = $.ajax({
        url: '/somepage',
        cache: false,
        type: GET
    });

That is if your problem is really with the cache.

13
  • when searching for the script using firebug, i see my script twice when i open the dialog again...
    – shay te
    Commented Jul 26, 2013 at 17:23
  • Your problem is probably not the cache and you should make a jsFiddle if you want more help. jsfiddle.com Commented Jul 26, 2013 at 17:28
  • jsFiddle don't like the idea of dynamically creating scripts. but i will paste a code snippet to my question
    – shay te
    Commented Jul 26, 2013 at 18:02
  • i can find any global ajax that will bring script along, and the cache flag is not helping .
    – shay te
    Commented Jul 26, 2013 at 18:24
  • Add more code to your question then. I can't help with what I can't see. Commented Jul 26, 2013 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.