AJAX 将“00”字符串截断为“0”
AJAX Truncating "00" string to "0"
所以我使用 ajax 传递值“00”,出于某种原因,当我的 WebMethod 收到字符串时,它只是“0” 我如何确保不会发生这种截断?
$.ajax({
url: 'http://localhost//Scripts/test.aspx/test',
type: 'POST',
data: JSON.stringify('{"tivId":"' +
$(e.relatedTarget).data('id') +
'","lotId":"' +
<%= LotId() %>
'"}'),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(response) {
SetSuccessModal();
},
failure: function(response) {
alert(response.d);
}
});
没有任何代码无法确定,但字符串可能会在传输前某处转换为整数。
尝试添加一些符号 tru:
"|00|"
然后在 webMethod 中删除它们
param.replace("|","");
这是一个暂时的快速解决方案,当然,如果您能找出发生这种情况的原因就更好了。
除此之外,日期类型可能会在此处引起问题,例如... int x = 00;// 这将存储为 0
所以我使用 ajax 传递值“00”,出于某种原因,当我的 WebMethod 收到字符串时,它只是“0” 我如何确保不会发生这种截断?
$.ajax({
url: 'http://localhost//Scripts/test.aspx/test',
type: 'POST',
data: JSON.stringify('{"tivId":"' +
$(e.relatedTarget).data('id') +
'","lotId":"' +
<%= LotId() %>
'"}'),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(response) {
SetSuccessModal();
},
failure: function(response) {
alert(response.d);
}
});
没有任何代码无法确定,但字符串可能会在传输前某处转换为整数。
尝试添加一些符号 tru:
"|00|"
然后在 webMethod 中删除它们
param.replace("|","");
这是一个暂时的快速解决方案,当然,如果您能找出发生这种情况的原因就更好了。
除此之外,日期类型可能会在此处引起问题,例如... int x = 00;// 这将存储为 0