我正在通过 jQuery 对GET
服务方法进行 Ajax 调用。问题是使用的参数的值可以包含/
字符,所以我决定使用该encodeURIComponent()
方法从参数中转义特殊字符。结果是/
字符被转换为%5
并试图在 Ajax 请求中使用转义参数。我的代码看起来像:
var id = "some/id";
$.ajax({
url: "http://www.mywebsite.com/getValue/" + encodeURIComponent(id),
dataType: "text",
type: 'GET',
async: true,
cache: false,
success: function (response, textStatus, jqXHR) {
alert("success");
},
error: function (jqXHR, textStatus, errorThrown) {
alert("error");
}
});
不知何故 jQueryunescapes
的 uri 值,没有调用服务器,我收到一个错误代码(如果参数中不存在,404 error
调用工作正常。/
知道如何在 Ajax 调用中发送此类参数,或者我的代码做错了什么吗?