?
Solved

Problems with Prototype and JSON parse in IE

Posted on 2008-10-27
1
Medium Priority
?
1,072 Views
Last Modified: 2013-11-11
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
Comment
Question by:exalkonium
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
Repus024 earned 1500 total points
ID: 22814558
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question