小猪之前写了这么个代码:1
2
3
4
5
6
7
8
9
10
11
12
13
14AJAX = function (data, url, beforesendfn, onsuccessfn, onerrorfn, oncomplete) {
$.ajax({
type: "POST",
url:url
cache: false,
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: beforesendfn,
success: onsuccessfn,
error: onerrorfn,
complete: oncomplete
});
}
这段代码实际上是没有什么问题的。
但是在调用代码的时候小猪使用了的参数1
var action = url == undefined ? "" : url;
这样在没有定义url的情况下url转换成“”。本意是想Post到当前页面地址。
在Chrome下和FireFox下都是没问题的,但是在IE下却不能post到对应地址。
所以为了兼容IE 小猪只好写了下述可怜的代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28AJAX = function (data, url, beforesendfn, onsuccessfn, onerrorfn, oncomplete) {
if (url == undefined || url == "") {
$.ajax({
type: "POST",
cache: false,
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: beforesendfn,
success: onsuccessfn,
error: onerrorfn,
complete: oncomplete
});
} else {
$.ajax({
type: "POST",
url:url,
cache: false,
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: beforesendfn,
success: onsuccessfn,
error: onerrorfn,
complete: oncomplete
});
}
}