#1
  1. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785

    Problem with jQuery and IE


    Hello,

    So I came here to ask why my JS code wont work (and wont give any errors) in IE8, however by transplanting my code to my test machine it stopped working in FF also. I tried to add some debugging code but alas the JSON method is not working and not giving me anything meaningful - could these two problems (IE and new dev copy FF) be related? The request URL for the JSON data is returining valid JSON to the browser when requested.

    Can someone tell me where to start debugging this? View source at

    http://ww.ioforge.com/testWidget.html
    Last edited by Matt1776; May 1st, 2013 at 04:47 PM.
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded
  2. #2
  3. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785
    OK I think i've found the problem with the FF issue - I was simply putting in 'ioforge.com/testWidget.html' - now after putting http://www.ioforge.com/testWidget.html it works fine.

    So now - why is it that IE 8 gives no errors and no love?
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded
  4. #3
  5. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785
    Apparently it works in IE9 but not IE8 - am I using an unsupported call that does not throw an error? //EDIT the link was broken - its now correct for FF but again does not work in IE8 and throws no console errors.
    Last edited by Matt1776; May 1st, 2013 at 04:47 PM.
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    Location
    Jakarta, Indonesia.
    Posts
    203
    Rep Power
    31
    Originally Posted by Matt1776
    Apparently it works in IE9 but not IE8 - am I using an unsupported call that does not throw an error? //EDIT the link was broken - its now correct for FF but again does not work in IE8 and throws no console errors.
    Probably adding
    PHP Code:
    header('Content-type: application/json'); 
    to review_widget.php might help?
  8. #5
  9. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785
    no apparently I have it down to the section here where I am looping through the results I get from the JSON call - i have the results but for some reason the iIter var and the aResult array are coming back with 0 and no length - this is a total mystery for me as it works fine in FF - all I am doing is pushing the jQuery objects into the array.

    Even more bizzare is why the iIter variable would be zero!
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded
  10. #6
  11. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785
    This code is baffling. Here is the relavent section and is returning zero for IE8 and normal count for FF:

    Code:
          displayReviews: function() {
            jQuery(document).ready(function($) {
              alert("going to call getJSON");
              $.getJSON(URL, function(rData) {
                alert("called getJSON - returned first id ["+rData.Result.Review[0]['Id']+"] ?");
                $.each(rData.Result.Review, function (index, review) {
                  if (!$.isEmptyObject(review.Comment) && review.iAnswer != 0) {
                    // load data array here
                  var review_div = $("<div>", {
                    id: "review_"+iIter,
                    style: "display: hidden;"}).html(review.Comment);
                    aReviews[iIter] = review_div;
                    iIter++;        
                  }
                  });
    
                if (rotateTimeout) {
                  window.clearTimeout(rotateTimeout)
                  rotateTimeout = null;
                }
    
                alert(iIter);
    
                console.log(aReviews);
                var cnt = aReviews.length;
                alert("count is " + cnt);
                if (cnt > 0) {
                  var init_div = $("<div>", {
                    id: "review_init", style: "display: hidden;"});
                  jQuery(init_div).appendTo(sContainerID);
                  UPReviewPlugin.nextReview();
                } else {
                  // display 'no reviews'
                  var nodisplay_div = $("<div>", {
                    id: "review_none"}).html("No Reviews to Dislpay");
                  jQuery(nodisplay_div).appendTo(sContainerID);
                }
    
              });
    
              // display header info
              var header_el = $("<span>", { id: "display_name" }).html(sShopDisplayName);
              jQuery(header_el).appendTo(sContainerHeaderID);
    
              // display footer info
              var footer_el = $("<a>", {
                href: "http://www.some-website.com"
              }).html("Powered by some-website.com");
              jQuery(footer_el).appendTo(sContainerFooterID);
    
            });
          },
    in IE 8 iIter comes back zero - which is baffling beyond all belief - its initialized as zero and is equal to the number of times $.each goes round in FF - as well as the length of the aReviews array. Here is a var dump of the aReviews array in FF's Firebug:

    Code:
    [{0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}, {0:{}, length:1}]
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded
  12. #7
  13. Recovering Intellectual
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    1,306
    Rep Power
    785
    OK the problem was with the use of the $.isEmptyObject method - the reason i use it here is due to the way XML is converted to JSON on the server - I end up with empty objects instead of empty strings. If I just check to see if the type is a string or an object I get what I need and I get support in IE and FF:

    Code:
    typeof review.Comment == 'object'
    Bugs that go away by themselves come back by themselves
    Beware - your loyalty will not be rewarded

IMN logo majestic logo threadwatch logo seochat tools logo