Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS: autoLoad does not work in IE

Using ExtJS 2.2.1, I've got a container element which is supposed to load a piece of HTML from the server using:

autoLoad: { url: 'someurl' }

This works fine in Firefox, but for IE7 this results in a syntax error in ext-all-debug.js at line 7170:

 this.decode = function(json){   
   return eval("(" + json + ')');
 };

I fixed this by turning that function into this:

 this.decode = function(json){   
    return eval('(function(){ return json; })()');  
 };

Then the autoLoad works well in both browsers, but then there's some odd bugs and besides, you really don't want to fix this in the ExtJS library as it will be unmaintainable (especially in the minified ext-all.js which is like half a megabye of Javascript on a single line).

I haven't been able to find a lot about this bug.

Variations that I've tried:

// With <script> tags around all the HTML
autoLoad: { url: 'someurl', scripts: true }
// With <script> tags around all the HTML
autoLoad: { url: 'someurl', scripts: false }

And visa versa without the <script> tags. There isn't any Javascript in the HTML either, but it should be possible, because eventually we will use Javascript inside the returned HTML.

The problem isn't in the HTML because even with the simplest possible HTML, the error is the same.

UPDATE - Response to donovan:

The simplest case where this is used is this one:

changeRolesForm = new Ext.Panel({
        height: 600,
        items: [{ autoScroll: true, autoLoad: WMS.Routing.Route("GetRolesList", "User")   + '?userID=' + id}]
    });

There is no datastore involved here. The response-type is also text\html, not json, so that can't be confusing it either. And as said, it's working just fine in Firefox, and in Firefox, it also executes the same eval function, but without the error. So it's not like Firefox follows a different path of execution, it's the same, but without the error on eval.

like image 632
JulianR Avatar asked Jun 30 '09 16:06

JulianR


2 Answers

Check your JSON. FF allow trailing commas in JSON objects while IE does not. e.g.

{foo:'bar',baz:'boz',}

would work in FF but in IE it would throw a syntax error. In order for there to not be a syntax error the JSON would need to be:

{foo:'bar',baz:'boz'}
like image 199
illvm Avatar answered Oct 27 '22 11:10

illvm


I located the source of the problem and it was indeed not with ExtJS. There was a section in the application that listened to the Ext.Ajax 'requestcomplete' event and tried decoding the response.responseText to json, even if the response was HTML (which it only is in one or two cases). IE was not amused by this.

like image 36
JulianR Avatar answered Oct 27 '22 09:10

JulianR