ExtJS:自动加载在 IE 中不起作用

发布于 2024-07-26 00:19:24 字数 1436 浏览 2 评论 0原文

使用 ExtJS 2.2.1,我有一个容器元素,它应该使用以下命令从服务器加载一段 HTML:

autoLoad: { url: 'someurl' }

这在 Firefox 中工作正常,但对于 IE7,这会导致 ext-all-debug.js 中出现语法错误在第 7170 行:

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

我通过将该函数变成这样来解决这个问题:

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

然后 autoLoad 在两个浏览器中都运行良好,但是还有一些奇怪的错误,此外,您真的不想在 ExtJS 库中修复这个问题,因为它将无法维护(尤其是在缩小的 ext-all.js 中,它的一行相当于半兆的 Javascript)。

我还没有找到很多关于这个错误的信息。

我尝试过的变体:

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

反之亦然,没有

问题不在于 HTML,因为即使使用最简单的 HTML,错误也是相同的。

更新 - 对 donovan 的响应:

使用此功能的最简单的情况是:

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

这里不涉及数据存储。 响应类型也是 text\html,而不是 json,因此也不会混淆。 如前所述,它在 Firefox 中工作得很好,并且在 Firefox 中,它还执行相同的 eval 函数,但没有错误。 所以这并不像 Firefox 遵循不同的执行路径,它是相同的,但没有 eval 上的错误。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

爱要勇敢去追 2024-08-02 00:19:25

我找到了问题的根源,确实不是ExtJS的问题。 应用程序中有一个部分侦听 Ext.Ajax 'requestcomplete' 事件并尝试将 response.responseText 解码为 json,即使响应是 HTML(仅存在于一两个中)例)。 IE对此并不好笑。

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.

吖咩 2024-08-02 00:19:25

如果您要自动加载到面板或元素中,那么该过程甚至不应该涉及 JSON 解码。 UpdateManager 只是遵循 Ext.Element.update(..) ,它接受一个 html 字符串。

我认为您的响应将被解析为 JSON 的唯一原因是,如果您使用 JSONStore 来请求它 - 您使用什么?

您应该能够执行如下简单操作:

var panel = new Ext.Panel({
  autoLoad: 'someurl'  // this is the short form, you can still use the object config
});

OR

var element = Ext.get('element id').update({
  url: 'someurl'
});

对更新的响应:

只要 WMS.Routing.Route(...) 方法没有发生奇怪的事情,这看起来就是正确的。 实际上,我目前正在自己​​开发 ExtJS 应用程序,因此我能够快速测试一些不同的服务器响应,并且无法重现您的问题。 我还重新查看了 ExtJS 2.2.1 源代码,但在相关的 Element update 和 UpdateManager 中仍然没有看到任何内容可以调用您所看到的 Ext.util.JSON.decode(...) 。

我想象它来自应用程序另一部分中不相关的 AJAX 请求。 如果您还没有,我会使用 firebug / firebug lite 来帮助调试它 - 特别尝试获取堆栈跟踪以确保问题的根源确实是此 autoLoad。

If you're autoLoad'ing into a Panel or Element then a JSON decode shouldn't even be involved in the process. UpdateManager just defers to Ext.Element.update(..) which takes a string of html.

The only reason I can think that your response would be parsed as JSON is if you were using a JSONStore to request it - what are you using?

You should be able to do something simple like this:

var panel = new Ext.Panel({
  autoLoad: 'someurl'  // this is the short form, you can still use the object config
});

OR

var element = Ext.get('element id').update({
  url: 'someurl'
});

Response to Update:

That looks correct as long as something weird isn't happening with the WMS.Routing.Route(...) method. I'm actually currently working on an ExtJS application myself so I was able to quickly test some different server responses and couldn't reproduce your problem. I've also relooked at the ExtJS 2.2.1 sources and still see nothing in the related Element update and UpdateManager that would make the call to Ext.util.JSON.decode(...) that you're seeing.

I'm imagining that its from an unrelated AJAX request in another part of your application. If you're not already, I would use firebug / firebug lite to help debug this - specifically try to get a stack trace to make sure the source of your problem really is this autoLoad.

晨与橙与城 2024-08-02 00:19:25

我也遇到了同样的问题,请原谅我的英语,我来自 Mejico,我希望我能提供帮助......当我提交表单登录时,我的问题被触发,我的 PHP 返回一个 JSON 以及响应,以防出现这样的失败:

$respuesta = "{success: false, msgError: 'El usuario o contraseña son incorrectos'}";

但是当它成功时,我没有发送响应,当它真正成功时,然后 ExtJS 它试图解码我的 JSON 响应,但没有什么可以解码,我想这就是我的情况,问题再次出现…我解决了,只是发回真正成功的响应,FF、Chrome、Safari,没有发现问题,但 Opera 和 IE8 却发现了…我希望我能帮助别人,再见

I had the same problem, excuse my english, i'm from Mejico, i hope I can help… my problem was triggered when I submit a Form to login, my PHP returns a JSON with the response in case of failure like this:

$respuesta = "{success: false, msgError: 'El usuario o contraseña son incorrectos'}";

but I wasn't send a resposne when it success, well when it has a true success, then the ExtJS it was trying to decode my JSON response, but there was nothing to decode, i guess that was, in my case again, the problem… I solved just sending back a response for the true succes, FF, Chrome, Safari, dont catch the problem, but Opera and IE8 does… I hope I help someone, goodbye

思念满溢 2024-08-02 00:19:25

我不知道问题是什么,但我想指出你的“修复”使它简单地返回 json 作为字符串而不是 eval'd 对象,所以当然不再有错误 - 你删除了功能。 它可能很简单:

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

一般来说,像这样的随机错误通常并不表明 Ext 中存在错误,尤其是在像 Ext.decode 这样常用的函数中。 我猜想,要么 JSON 中有一些 IE 不喜欢其他浏览器忽略的内容,要么更有可能的是,您的应用程序中发生了一些意外的情况,从您的描述来看并不明显。 您是否尝试过在 Firebug 中检查请求日志以查看 JSON 的实际情况? 您是否尝试过先将 Route 调用的结果放入变量中,以在填充面板之前验证其内容? 另外,尝试将 Firebug 中的“break on allerrors”选项设置为 true——很多时候,当您从堆栈跟踪顶部的 Ext 获得随机函数时,罪魁祸首实际上是一些您不是的应用程序代码期待。

I don't know what the problem is, but I wanted to point out that your "fix" makes it simply return the json as a string instead of an eval'd object, so of course there is no error anymore -- you removed the functionality. It could just as simply be:

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

Generally speaking, random errors like this do not usually indicate a bug in Ext, especially not in functions used as commonly as Ext.decode. I would guess that either there is something in the JSON that IE does not like that other browsers ignore, or more likely, there is something unexpected going on in your app that is not obvious from your description. Have you tried inspecting your request log in Firebug to see what the JSON actually looks like? Have you tried getting the result of your Route call into a variable first to verify its contents before populating the panel? Also, try setting the "break on all errors" option in Firebug to true -- a lot of times when you get a random function from Ext at the top of your stack trace, the culprit is actually some application code that you weren't expecting.

王权女流氓 2024-08-02 00:19:24

检查你的 JSON。 FF 允许在 JSON 对象中使用尾随逗号,而 IE 则不允许。 例如

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

在 FF 中可以工作,但在 IE 中会抛出语法错误。 为了不出现语法错误,JSON 需要是:

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

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'}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文