Ajax 使用 Internet Explorer 11 发送数据时出错 - "SCRIPT65535 argument not optional"

Ajax error when sending data with Internet Explorer 11 - "SCRIPT65535 argument not optional"

我在通过 AJAX 发送数据时遇到问题,它适用于所有浏览器,但在 IE 11 上它给出了一个错误。

这是我的功能addToCart。 有一些参数和一个JSON。 当我尝试发送数据时,出现此错误消息。

我也尝试将 cache=false 属性设置为 ajax,但没有任何改变。

function addToCart(productId, userId) {

var colorId = getColorId();

var jsonObj = [];

item = {}
item["Size"] = "M";
item["Quantity"] = parseInt(2);

jsonObj.push(item);

$.ajax({
    dataType: "json",
    type: "post",
    url: "/Cart/AddToCart",
    contenttype: 'application/json; charset=utf-8',
    async: true,
    cache: false,
    data: {
        "productId": productId, "color": colorId, "userId": userId, "sizesQty": jsonObj },
    beforeSend: function () {
        
    },
    success: function (data) {
        
    },
    error: function (xhr) {
        
    }
})

}

你有什么解决办法吗?

谢谢!

我在 IE 11 中测试了您的代码并重现了该问题。我发现你没有在函数中声明变量 item 。 IE对语法比较严格。声明变量后,在IE下可以正常运行:

var item = {};
item["Size"] = "M";
item["Quantity"] = parseInt(2);