我们使用 jquery ajax 来进行服务 get 调用:
$.ajax({
url: _sbUrl + "gates/1.0/sweeps/getVehicleDetails/" + request.data.regn_no,
method: "GET",
success: function(response) {
if (200 === response.statusCode) {
if (typeof callback === 'function') callback(response);
} else if (typeof callback === 'function') callback({});
},
error: function(response) {
if (typeof callback === 'function') callback({});
}
});
这里使用_sbUrl
http://192.32.45.34:9090/
。
当调用时,url 会更新为这样
http://localhost/web/guest/%22http://192.32.45.34:9090/%22gates/1.0/sweeps/getVehicleDetails/DE3SA2323
这只发生在 IE10 及以下版本的 IE 上,而在所有其他浏览器上工作正常。 我尝试过:
- 对网址进行编码
- 添加了
crossdomain = true
但它们都不起作用。这是 jQuery 的已知错误吗?如果是,我们是否有解决方法。
最佳答案
根据 @Archer 的建议,问题出在 _sbUrl
上。
Url 是从属性文件中作为字符串获取的,对于 IE10,它还包含引号。
因此 http://192.32.45.34:9090/
被获取为 "http://192.32.45.34:9090/"
_sbUrl = _sbUrl.replace(/\\\//g, "/");
@Archer 的推论是由于 %22http://192.32.45.34:9090/%22
具有 %22
(相当于“)作为前缀和后缀。
关于jquery - 使用jquery ajax将本地url连接到绝对url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49189673/