Reputation: 1068
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 .
Upvotes: 1
Views: 216
Reputation: 2417
This should do the trick:
var html = $.ajax({
url: '/somepage',
cache: false,
type: GET
});
That is if your problem is really with the cache.
Upvotes: 2