All, I knew we can use the load method to load dynamic content into a div. But In my case , I found an issue when used it . If you want to load the same page which contains some external js files in the exactly same page. you will find the same js will be loaded for twice times. one for the first time to open the page , second for when ajax load the same page. so I think there will exist some potential problem for this case . for example if you set a value for a variable in JavaScript which is initialized in js file, after load the page, you will find it would be reverted to the initialized value.. One of the solution I can find is using IFrame ,Is there any good way to make it ? thanks.
the code would looks like below.
in test.html
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="test.js"></script>
<script type="text/javascript">
$(function(){
$("#loadBtn").on("click", function(event)
{
$('#container').load('test.html');
});
$("#getTest").on("click", function(event)
{
alert(test);
});
$("#changeTest").on("click", function(event)
{
test="changed";
});
});
</script>
</head>
<body>
<div id="container" style="width:200px;height:200px; padding:10px; border:1px solid black;"></div>
<input type="button" id="loadBtn" value ="Load"/>
<input type="button" id="getTest" value="gettest"/>
<input type="button" id="changeTest" value="changetest"/>
</body>
</html>
in test.js
var test="1";