【发布时间】:2016-11-07 06:45:04
【问题描述】:
$scope.updateCart = function() {
item = $scope.productData;
这段代码 sn-p 在 IE 11 中返回一个函数,而不是像在 chrome 上那样返回对象
导致下面的 $http 请求发送乱码数据。
使用https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js
上一个标题:IE 11 jquery 'Argument not optional' 错误
以下代码:
dt = $.param({
shopid: shop_id,
mtd: method,
item: item
});
抛出以下错误:
TypeError: Argument not optional
at add (https://code.jquery.com/jquery-1.9.1.js:7340:4)
at buildParams (https://code.jquery.com/jquery-1.9.1.js:7392:3)
at jQuery.param (https://code.jquery.com/jquery-1.9.1.js:7360:4)
at $scope.updateBACart (http://127.0.0.1:6636/js/baCartNg.js?v=1478430971:104:3)
at fn (Function code:2:216)
at expensiveCheckFn (http://code.angularjs.org/1.5.5/angular.js:15485:11)
at callback (http://code.angularjs.org/1.5.5/angular.js:25018:17)
at Scope.prototype.$eval (http://code.angularjs.org/1.5.5/angular.js:17229:9)
at Scope.prototype.$apply (http://code.angularjs.org/1.5.5/angular.js:17329:13)
at Anonymous function (http://code.angularjs.org/1.5.5/angular.js:25023:17)
错误在 IE 11 中抛出,但在 chrome 中没有
根据https://docs.angularjs.org/api/ng/service/$httpParamSerializerJQLike
我改代码:
dt = $httpParamSerializerJQLike({
shopid: shop_id,
mtd: method,
item: item
});
现在代码没有抛出错误,但是请求是
item: %0Afunction+item()+%7B%0A++++%5Bnative+code%5D%0A%7D%0A
mtd: add
shopid: 1
而不是项目数据。
【问题讨论】:
-
从最后一个 sn-p 的输出来看,您的
item变量实际上包含一个 函数。也许您只是忘记调用该函数,例如var item = elements.item之类的东西应该是var item = elements.item(0)?尝试在该行之前添加console.log(item)并查看浏览器控制台中记录的内容。 -
我注意到,这是我从 NG 范围获得的值 - 这在 IE 11(与 chrome 相比)中是错误的
-
奇怪的是 IE 和 Chrome 会有所不同。我认为您需要向我们展示更多代码,以便其他人可以更好地了解您的变量发生了什么。
-
我的猜测是,这实际上与 IE 和 Chrome 本身之间的差异无关,而更像是一种竞争条件,其中
item是别的东西(承诺,也许)当执行速度变化时。查看更多代码肯定有助于确定确切的问题。 -
始终提供minimal reproducible example。显示的 sn-ps 只让人们猜测,第一个非常不完整
标签: jquery angularjs internet-explorer-11