javascript Ajax SCRIPT1003:在 IE 11 中应为“:”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35808557/
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
javascript Ajax SCRIPT1003: Expected ':' in IE 11
提问by Mario Zanetta
var url="tabla.php";
$.ajax({
type: "POST",
url:url,
data:{place,names,repor},
success: function(datos){
$('#tabla').html(datos);
}
This code works in Chrome but in IE 11 returns the error SCRIPT1003: Expected ':'
on line 5. I'd really appreciate any help.
这段代码在 Chrome 中有效,但在 IE 11 中返回第SCRIPT1003: Expected ':'
5 行的错误。我真的很感激任何帮助。
Note:place
and names
are arrays that are previously defined, and repor
is also a previously defined variable.
注意:place
andnames
是之前定义的数组,repor
也是之前定义的变量。
回答by ryan
Usually objects in javascript are initialized as key value pairs, so data should probably be initialized like
通常 javascript 中的对象被初始化为键值对,因此数据可能应该像这样初始化
data:{ place : place, names : names, report : report }
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer
请参阅https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer
In ECMAScript 2015 it seems you can omit the key part in certain situations, which is why it works on chrome.
在 ECMAScript 2015 中,您似乎可以在某些情况下省略关键部分,这就是它适用于 chrome 的原因。
回答by pursang
I had the SCRIPT1003: Expected ':' error as well in IE 11 (and my code worked fine in Chrome & FireFox). If someone uses Knockoutjs and encounters this, watch out for the syntax when stating functions in your view model:
我在 IE 11 中也有 SCRIPT1003: Expected ':' 错误(我的代码在 Chrome 和 FireFox 中运行良好)。如果有人使用 Knockoutjs 并遇到这种情况,请注意在视图模型中声明函数时的语法:
var viewModel = {
property1: "",
functionWorksInAllBrowsers: function (arg1, arg2) {
// ...
},
functionThrowsErrorInInternetExplorer11(arg1, arg2) {
//...
}
};