javascript Ajax SCRIPT1003: Expected ':' in IE 11

可紊 提交于 2019-12-22 02:51:58

问题


 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.

Note: place and names are arrays that are previously defined, and repor is also a previously defined variable.


回答1:


Usually objects in javascript are initialized as key value pairs, so data should probably be initialized like

data:{ place : place, names : names, report : report }

See 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.




回答2:


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:

var viewModel = {
    property1: "",
    functionWorksInAllBrowsers: function (arg1, arg2) {
        // ...
    },
    functionThrowsErrorInInternetExplorer11(arg1, arg2) { 
        //...
    }
};


来源:https://stackoverflow.com/questions/35808557/javascript-ajax-script1003-expected-in-ie-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!