Ajax 请求问题:错误 80020101

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4918969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 10:57:17  来源:igfitidea点击:

Ajax request problem: error 80020101

ajaxinternet-explorerjspjspinclude

提问by Ali

I have a request which returns a jsp page. But the fact is, the jsp includes jsp:include in it(it calls another jsp file in it) and ie gives the error 80020101.

我有一个返回一个jsp页面的请求。但事实是,jsp 中包含 jsp:include(它调用了其中的另一个 jsp 文件)并且 ie 给出了错误 80020101。

Any ideas?

有任何想法吗?

Thanks

谢谢

采纳答案by heikkim

Remove javascript declarations that imports a script using src-attribute. Change your javascript-file to inline-javascript if you really need it there.

删除使用 src-attribute 导入脚本的 javascript 声明。如果您真的需要它,请将您的 javascript-file 更改为 inline-javascript 。

Source:http://bytes.com/topic/javascript/answers/750333-ie-syntax-error-80020101-undefined-array

来源:http : //bytes.com/topic/javascript/answers/750333-ie-syntax-error-80020101-undefined-array

Easiest way to would be to to add a parameter to your AJAX request such as ajax=1and hide the javascript declarations when ajax-parameter exists is in request.

最简单的方法是向您的 AJAX 请求添加一个参数,例如ajax=1并在请求ajax-parameter 存在时隐藏 javascript 声明。

I don't think this has anything to do with including files with jsp:include since the browser does not know aynthing else than the HTML you throw it with.

我认为这与使用 jsp:include 包含文件没有任何关系,因为浏览器除了您抛出的 HTML 之外不知道其他任何内容。

回答by Volomike

You can also get this error if you're doing an AJAX call from jQuery and you pass an extra comma on the end of the array, like so:

如果您从 jQuery 执行 AJAX 调用并且在数组末尾传递一个额外的逗号,您也可能会收到此错误,如下所示:

$.post('http://example.com/example1/',{
  field1:sField1,
  field2:sField2,
  field3:sField3,
  field4:sField4,
  field5:sField5,
},function(sData){
  if (console) { console.log(sData); }
});

See that comma after the sField5? That's the syntax error. No other browser will care but IE. IE will throw the obscure 80020101 error (which means "cannot evaluate your Javascript -- you have a syntax error") and it will be practically baffling to chase it down if you're using jQuery because the debugger will merely point to the eval line in jQuery. The IE debugger will be of no use to you to chase this, thanks to Microsoft. The next time you get the 80020101 error, my suggestions are:

看到 sField5 后面的逗号了吗?那是语法错误。没有其他浏览器会关心,但 IE。IE 将抛出模糊的 80020101 错误(这意味着“无法评估您的 Javascript - 您有一个语法错误”)并且如果您使用 jQuery,实际上追它会莫名其妙,因为调试器只会指向 eval 行在 jQuery 中。多亏了微软,IE 调试器对你来说没有用。下次您收到 80020101 错误时,我的建议是:

  1. Look for any AJAX calls and look for an extra comma.
  2. Look for any arrays (like stuff in curly braces) where there's an extra comma at the end.
  3. If that still doesn't help, then look at the technique where you use <!--and //-->to mark off your Javascript. This has been a known problem with jQuery up until 1.7.2 and it's still a filed bug with the jQuery team.
  4. Move to the latest version of jQuery.
  5. Start removing stuff piece by piece out of your script block and adding the items in slowly until you find the offending piece of code.
  1. 查找任何 AJAX 调用并查找额外的逗号。
  2. 查找末尾有额外逗号的任何数组(如花括号中的内容)。
  3. 如果这仍然没有帮助,请查看您使用的技术<!--//-->标记您的 Javascript。在 1.7.2 之前,这一直是 jQuery 的一个已知问题,它仍然是 jQuery 团队提交的错误。
  4. 移至最新版本的 jQuery。
  5. 开始从脚本块中逐个删除内容,然后慢慢添加项目,直到找到有问题的代码段。

回答by DevlshOne

I have now come across this problem with jQuery (even the latest version) twice. The ONLY solution is to copy and paste allof your javascript into onebig file and run it through JSLint (jsfiddle.net, preferred). It was able to point out several minor errors (including an extra commain one of my data callback structures) that I was able to fix and then re-copy and paste back into their original places to eliminate the issue.

我现在已经两次使用 jQuery(甚至是最新版本)遇到这个问题。唯一的解决方案是将所有javascript复制并粘贴到一个大文件中,然后通过 JSLint(jsfiddle.net,首选)运行它。它能够指出我能够修复的几个小错误(包括我的数据回调结构中的一个额外逗号),然后重新复制并粘贴回其原始位置以消除该问题。

http://jsfiddle.net/devlshone/QKxup/3/

http://jsfiddle.net/devlshone/QKxup/3/

回答by ManGysT

I had the same error, but in my case there was a reserved word 'class'. Here is a snippet of code to make this clear:

我有同样的错误,但就我而言,有一个保留字'class'。下面是一段代码来说明这一点:

function foo(ajaxResponse){
  $(elem).attr('class', ajaxResponse.class);
}

I rewrote this as:

我把它改写为:

$(elem).attr('class', ajaxResponse['class']);

Hope this was helpful.

希望这是有帮助的。

回答by Arvind Bhardwaj

In my case I found that there was an HTML comment in my JS code as:

就我而言,我发现我的 JS 代码中有一个 HTML 注释:

<script type="text/javascript">
<!-- Unexpected Comment -->
//code...
</script>

I replaced <!-- -->with /* */and it worked. Hope it will help someone.

我替换<!-- -->/* */它并且它起作用了。希望它会帮助某人。

回答by janoulle

I ran into this issue and IE's error messages weren't very helpful. So, I visited my site in Mozilla Firefox and Firefox was able to pinpoint the exact line of code that was problematic. Not a high tech fix but if you have been using just IE for debugging this issue, try loading your site in FF (with the Firebug extension installed) and checking the console output.

我遇到了这个问题,并且 IE 的错误消息不是很有帮助。因此,我在 Mozilla Firefox 中访问了我的网站,Firefox 能够查明有问题的确切代码行。不是高科技修复,但如果您一直只使用 IE 来调试此问题,请尝试在 FF 中加载您的站点(安装 Firebug 扩展)并检查控制台输出。

回答by aakash jalodkar

I also ran into this issue, but after taking a close look at my script file, I found out that I made a small mistake that run smoothly on other browser but IE pick it and show me the error:

我也遇到了这个问题,但是仔细查看我的脚本文件后,我发现我犯了一个小错误,在其他浏览器上运行流畅,但 IE 选择了它并显示错误:

My previous code was:

我之前的代码是:

var autocomplete = new google.maps.places.Autocomplete(searchTextField ,options);

After analyzing, I got that searchTextFieldis id and I have to get its value before using it

分析后,我得到了那个searchTextFieldid,我必须在使用它之前获取它的值

So I change it to:

所以我把它改成:

var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input,options);

and it works fine.

它工作正常。

That's really cool that IE detects it, but Microsoft may enhance the browser to show specific error for specific cause, because it's very frustrating if same code works in other browsers

IE 检测到它真的很酷,但是 Microsoft 可能会增强浏览器以显示特定原因的特定错误,因为如果相同的代码在其他浏览器中工作,这将非常令人沮丧

回答by 1_bug

In my case the problem was additional useless coma in Ajax POST in the end of error function:

在我的情况下,问题是错误函数末尾的 Ajax POST 中额外的无用昏迷:

$.ajax({
     type: 'POST',
     dataType: 'text',
     url: '../Client/GetName',
     data: { ClientId: id},
     success: function (respone) {
                alert(respone);
     },
     error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.statusText);
     }, //<- look here, this guy complicated my simple programmer life
 });

After removed it everything works fine.

删除后一切正常。

回答by Shilpa R

I had missed to put 'var' in front of variable declaration, putting that it solved the issue.

我错过了将“var”放在变量声明前面,认为它解决了问题。

<script>
    uploadDocument = "Some message";
</script>

I fixed it to :

我把它固定为:

var uploadDocument = "Some message";

Root cause was that I had an element in the form with the same id "uploadDocument", hence the above declaration was causing the html to be malformed

根本原因是我在表单中有一个具有相同 ID“uploadDocument”的元素,因此上述声明导致 html 格式错误

回答by Clyde Lobo

Are you by any chance including a js file ?

您是否有机会包含一个 js 文件?

Because

因为

Error 80020101 means that IE isnt't able to compile your script.

错误 80020101 表示 IE 无法编译您的脚本。