window.execScript在ie8中失败 [英] window.execScript fails in ie8

查看:269
本文介绍了window.execScript在ie8中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jquery 1.9.1在ruby on rails(3.2.11)上工作...在我的应用程序中,我使用javascript开发了聊天功能.

I work in ruby on rails (3.2.11) with jquery 1.9.1... in my app I developed a chat in javascript.

使用IE9,一切正常,在IE8中调用

With IE9 all is ok, in IE8 when calling

function refresh_contacts() {       
 url = $('#refresh_contacts_url').val()
 $.ajax(url)
}

我得到了该主题的错误...我试图找出问题所在,似乎是ajax调用(即使被调用的函数上没有代码,也只是调用,所以我认为这是调用本身提出问题)...

I get the error in the subject... I tried to isolate the problem and it seems it's the ajax call (just the call, even if there is no code on the called function, so I think it's the call itself who raise the problem)...

引发错误的代码(如IE调试器所示)在jquery中(第603行未缩小,版本1.9.1):

The code which raise the error (as indicated by the IE debugger) is in jquery (around line 603 non minified, version 1.9.1):

globalEval: function( data ) {
    if ( data && jQuery.trim( data ) ) {
        // We use execScript on Internet Explorer
        // We use an anonymous function so that context is window
        // rather than jQuery in Firefox
        ( window.execScript || function( data ) {
            window[ "eval" ].call( window, data );
        } )( data );
    }
},

我尝试了一些在网上找到的变通方法,例如使用async:false并使用XMLHttpRequest作弊,没有运气...

I tried several workarounds I found on the net like using async: false and cheating with the XMLHttpRequest, with no luck...

Tnx, 法比奥

推荐答案

实际上,问题出在window[ "eval" ].call( window, data )调用的代码指令中.

In fact the problem is located in a code instructions called by the window[ "eval" ].call( window, data ).

解决此问题的最佳方法是在Edge或IE中使用开发人员工具,并在有呼叫的线路上放置一个断点.然后,您将可以看到 data 变量中的内容.复制 data 的内容,并将其放入一些js验证器中(例如 esprima验证器).它应该显示IE出现问题的行.然后更正您的代码,您就可以开始了!

The best way to solve this problem is to use Developer Tools in Edge or IE and place a breakpoint on the line with a call. Then You'll be able to see, what's inside the data variable. Copy the contents of data and put it into some js validator (for example esprima validator). It should display problematic lines for IE. Then correct Your code and You're ready to go!

这篇关于window.execScript在ie8中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆