Jump to content

New data only when debugger on


Gerhard

Recommended Posts

Hi,

 

have now a running version of a script. Does get data correct from server, but only once.

Repeat hitting 'View' button doesnt produce new data requests (checked this by having a breakpoint on my servers C# code). After pressing F12 and invoking the debugger within IE11, each hit of 'View' sends a request to the server.

Any idea?

 

Script in the attachment.

 

With best regards

 

Gerhard

JsonViewer.html

Link to comment
Share on other sites

i used your script + some miner changes ,i used the json from http://www.w3schools.com/appml/customers.php .made some change to listJson function .

 

using IE 8 i replaced document.getElementById("demo").innerHTML = text; by $('#demo').html(text); and it works .

 

heres the script :

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="dcterms.created" content="Di, 29 Dez 2015 22:56:32 GMT">
    <meta name="description" content="GeoMon Template Page">
    <meta name="keywords" content="Just a template">
	  <meta content="text/html; charset=utf-8" http-equiv="content-type" />
  	<meta name="viewport" content="width=device-width, initial-scale=1">
  	<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  	<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <title>Json Viewer</title>
  </head>
<body>

<p>The best way to loop through an array is using a standard for loop:</p>

<button onClick="readFromServer('http://www.w3schools.com/appml/customers.php')">Try it</button>

<p id="demo"></p>

<script>
function listJson( content )
	{
	  var index, text = "<ul>";
		for (index = 0; index < content.records.length; index++)
		text += "<li>" + content.records[index].CustomerName + "  " + content.records[index].City + "</li>";
    text += "</ul>";
    $('#demo').html(text);
	//document.getElementById("demo").innerHTML = text;
	}
  function readFromServer(url)
		{
			var xmlhttp = new XMLHttpRequest();
      xmlhttp.onreadystatechange = 
				      function() 
							  { 
				          if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
						  {
						   document.getElementById("demo").innerHTML = "";
						   setTimeout(function(){  listJson(JSON.parse(xmlhttp.responseText)); }, 3000);
						    	
						  } 
				        };
       xmlhttp.open("GET", url, true);
       xmlhttp.send();
		 }
		 
	
</script>

</body>
</html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...