解决方案如下

1、ie9以下兼容ajax跨域访问  
2、ajax请求开始前添加 jQuery.support.cors = true;  允许跨域
3、ie浏览器设置允许通过访问数据 并且 urlhttp协议。(设置=>Internet选项=>安全=>自定义级别=>允许通过访问数据设置启用))

示例

                jQuery.support.cors = true;
				$.ajax({
					type: "GET",
					//             cache: false,
					data: {

					},
					url: url, //请求地址
					dataType: "json",
					success: function(res) {
						console.log(res)
					},
					error: function(err) {
						console.log(err)
					}
				});

以上设置后,如果请求参数中携带有中文,将会报400错误

解决方法:将传递的参数进行编码然后传递给后台js编码encodeURI(中文参数),

                jQuery.support.cors = true; //浏览器支持跨域访问
				var name = encodeURI('泰顺县') //兼容IE浏览器传递中文解码可以正常请求
				$.ajax({
					type: "GET",
					//cache: false,
					url: 'http://www.xxxxxx/get?city=' + name, //请求地址
					dataType: "json",
					success: function(res) {
						console.log(res)
					},
					error: function(err) {
						console.log(err)
					}
				});

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注