• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1080
  • Last Modified:

Problems with Prototype and JSON parse in IE

Hello Experts,

I am trying to develop a dynamically loaded section of a web page. The main content of a div is loaded via AJAX using Prototype's 1.6 library. I load a PHP page into this div, which contains a script tag at the end to call a function that will load more content into a particular div on the PHP page. The JS script uses a Prototype Ajax.Request to call another JS file which includes JSON data, all-in-all about 30 objects contained in a single array. I loop through the JSON data which just prints a little box for each JSON object: which works fine in Firefox. In IE though, it does absolutely nothing. In my debugging, I have found that the script does run, but once I try to run evalJSON() on the responseText, the function will not run anything else, and the function either never runs or never completes. IE does not return an error. I am wondering if there is some sort of file size or length issue, but I can't be for sure. I have also checked for valid JSON and checked for trailing commas, but there are none. Please help, and see bits of source code.
Here is one JSON object out of the 30 in the file:
====================================================
{
	"list" : [
		{	
			"title" : "403(b) Plans",
			"file" : "403bp.php",
			"video" : false,
			"videourl" : "",
			"article" : false,
			"articleurl" : "",
			"b1" : false,
			"b2" : false,
			"b3" : false,
			"b4" : true,
			"b5" : false
		}
       ]
}
 
 
 
 
Here is the important section of the PHP page:
===============================================
echo "<h1><strong>Reference Library</strong></h1>
     <div id=\"references\">
								
     </div>
 
<script type=\"text/javascript\">
	list_references();
</script>
";
 
Here is the function in the JS for the function call right above:
==================================================================
function list_references() {
 new Ajax.Request('referencelibraryJSON.php', {
  method:'get',
  onSuccess: function(transport) {
    references = transport.responseText.evalJSON();
    references.list.each(function(item) {
      line1 = "<div class='refbox'>" + item.title + "<br />";
      line2 = "<div class='refbook'><a href='" + item.file + "' rel='iframe' class='lightview' title='" + item.title + " :: Reference Library :: autosize: true, scrolling:true'><img src='images/book.jpg' /></a></div>";
      line3 = "<a href='b1.php' rel='ajax' class='lightview' title='Bucket One :: Reference Library :: autosize:true, scrolling:true'><img src='images/1icon.jpg' class='reficon' /></a>";
      line4 = "<a href='b2.php' rel='ajax' class='lightview' title='Bucket Two :: Reference Library :: autosize:true, scrolling:true'><img src='images/2icon.jpg' class='reficon' /></a>";
      line5 = "<a href='b3.php' rel='ajax' class='lightview' title='Bucket Three :: Reference Library :: autosize:true, scrolling:true'><img src='images/3icon.jpg' class='reficon' /></a>";
      line6 = "<a href='b4.php' rel='ajax' class='lightview' title='Bucket Four :: Reference Library :: autosize:true, scrolling:true'><img src='images/4icon.jpg' class='reficon' /></a>";
      line7 = "<a href='b5.php' rel='ajax' class='lightview' title='Bucket Five :: Reference Library :: autosize:true, scrolling:true'><img src='images/5icon.jpg' class='reficon' /></a>";
      line8 = "<a href='" + item.articleurl + "' rel='ajax' class='lightview' title='Corporate 401(k) :: Reference Library :: autosize:true, scrolling:true'><img src='images/aicon.jpg' class='reficon' /></a>";
      line9 = "<a href='" + item.videourl + "' rel='ajax' class='lightview' title='Corporate 401(k) :: Reference Library :: autosize:true, scrolling:true'><img src='images/vicon.jpg' class='reficon' /></a>";
      line10 = "</div>";
					
      inserter = line1 + "" + line2;
      if (item.b1 == true) { inserter = inserter + "" + line3; }
      if (item.b2 == true) { inserter = inserter + "" + line4; }
      if (item.b3 == true) { inserter = inserter + "" + line5; }
      if (item.b4 == true) { inserter = inserter + "" + line6; }
      if (item.b5 == true) { inserter = inserter + "" + line7; }
      if (item.article == true) { inserter = inserter + "" + line8; }
      if (item.video == true) { inserter = inserter + "" + line9; }
      inserter = inserter + "" + line10;
      $('references').insert({ 'bottom' : inserter });
    });
    Lightview.updateViews();
   }
  });
}

Open in new window

0
exalkonium
Asked:
exalkonium
1 Solution
 
Repus024Commented:
IE will cache get requests with the same URL.  I suspect that is what is happening here.  Append a random number to your URL and see if that helps.  Try something like the attached code snippet

Please let me know if this does not fix the situation.
Here is one JSON object out of the 30 in the file:
====================================================
{
        "list" : [
                {       
                        "title" : "403(b) Plans",
                        "file" : "403bp.php",
                        "video" : false,
                        "videourl" : "",
                        "article" : false,
                        "articleurl" : "",
                        "b1" : false,
                        "b2" : false,
                        "b3" : false,
                        "b4" : true,
                        "b5" : false
                }
       ]
}
 
 
 
 
Here is the important section of the PHP page:
===============================================
echo "<h1><strong>Reference Library</strong></h1>
     <div id=\"references\">
                                                                
     </div>
 
<script type=\"text/javascript\">
        list_references();
</script>
";
 
Here is the function in the JS for the function call right above:
==================================================================
function list_references() {
 new Ajax.Request('referencelibraryJSON.php', {
  method:'get',
  parameters: {noCacheDummy: Math.random()},
  onSuccess: function(transport) {
    references = transport.responseText.evalJSON();
    references.list.each(function(item) {
      line1 = "<div class='refbox'>" + item.title + "<br />";
      line2 = "<div class='refbook'><a href='" + item.file + "' rel='iframe' class='lightview' title='" + item.title + " :: Reference Library :: autosize: true, scrolling:true'><img src='images/book.jpg' /></a></div>";
      line3 = "<a href='b1.php' rel='ajax' class='lightview' title='Bucket One :: Reference Library :: autosize:true, scrolling:true'><img src='images/1icon.jpg' class='reficon' /></a>";
      line4 = "<a href='b2.php' rel='ajax' class='lightview' title='Bucket Two :: Reference Library :: autosize:true, scrolling:true'><img src='images/2icon.jpg' class='reficon' /></a>";
      line5 = "<a href='b3.php' rel='ajax' class='lightview' title='Bucket Three :: Reference Library :: autosize:true, scrolling:true'><img src='images/3icon.jpg' class='reficon' /></a>";
      line6 = "<a href='b4.php' rel='ajax' class='lightview' title='Bucket Four :: Reference Library :: autosize:true, scrolling:true'><img src='images/4icon.jpg' class='reficon' /></a>";
      line7 = "<a href='b5.php' rel='ajax' class='lightview' title='Bucket Five :: Reference Library :: autosize:true, scrolling:true'><img src='images/5icon.jpg' class='reficon' /></a>";
      line8 = "<a href='" + item.articleurl + "' rel='ajax' class='lightview' title='Corporate 401(k) :: Reference Library :: autosize:true, scrolling:true'><img src='images/aicon.jpg' class='reficon' /></a>";
      line9 = "<a href='" + item.videourl + "' rel='ajax' class='lightview' title='Corporate 401(k) :: Reference Library :: autosize:true, scrolling:true'><img src='images/vicon.jpg' class='reficon' /></a>";
      line10 = "</div>";
                                        
      inserter = line1 + "" + line2;
      if (item.b1 == true) { inserter = inserter + "" + line3; }
      if (item.b2 == true) { inserter = inserter + "" + line4; }
      if (item.b3 == true) { inserter = inserter + "" + line5; }
      if (item.b4 == true) { inserter = inserter + "" + line6; }
      if (item.b5 == true) { inserter = inserter + "" + line7; }
      if (item.article == true) { inserter = inserter + "" + line8; }
      if (item.video == true) { inserter = inserter + "" + line9; }
      inserter = inserter + "" + line10;
      $('references').insert({ 'bottom' : inserter });
    });
    Lightview.updateViews();
   }
  });
}

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now