M
max
Hello,
Based on various posts, I've come up with the following code to load
data into a js array dynamically without a screen refresh. It works,
but you have to push the button twice before it shows the new data that
you have changed in the js file. It's almost like something is being
cached. Can anyone help? Following is the code from the php and js
file:
test.php
------------
<html>
<head>
<script id="mydata" src="test.js" type="text/javascript"></script>
<script>
var mysplitdata;
function refresh_data () {
document.getElementById('mydata').src='test.js?x=' +
Math.random();
mysplitdata = myData.split(",");
}
</script>
</head>
<body>
<button
onclick="refresh_data();document.getElementById('mydiv').innerHTML=mysplitdata[2];">Click
Me</button>
<div id="mydiv" style="border: 1px solid
black;height:100px;width:300px;"></div>
</body>
</html>
test.js
---------
var myData = "name1,name2,name3";
So basically, if you change element 'name3' in test.js to let's say,
"testname", then click on the button on test.php, nothing happens
although you see the loading action at the bottom of the screen.
However, hit the button again and the you will see "testname".
Can anyone tell me why this is happening? How can I click the button
once to get the new data?
Thanks,
Max
Based on various posts, I've come up with the following code to load
data into a js array dynamically without a screen refresh. It works,
but you have to push the button twice before it shows the new data that
you have changed in the js file. It's almost like something is being
cached. Can anyone help? Following is the code from the php and js
file:
test.php
------------
<html>
<head>
<script id="mydata" src="test.js" type="text/javascript"></script>
<script>
var mysplitdata;
function refresh_data () {
document.getElementById('mydata').src='test.js?x=' +
Math.random();
mysplitdata = myData.split(",");
}
</script>
</head>
<body>
<button
onclick="refresh_data();document.getElementById('mydiv').innerHTML=mysplitdata[2];">Click
Me</button>
<div id="mydiv" style="border: 1px solid
black;height:100px;width:300px;"></div>
</body>
</html>
test.js
---------
var myData = "name1,name2,name3";
So basically, if you change element 'name3' in test.js to let's say,
"testname", then click on the button on test.php, nothing happens
although you see the loading action at the bottom of the screen.
However, hit the button again and the you will see "testname".
Can anyone tell me why this is happening? How can I click the button
once to get the new data?
Thanks,
Max