我使用 REST 和 ajax 使用 ablve 从 SharePoint 获取数据:
https:xxxxxxxx/_vti_bin/ListData.svc/RMSD_Tasks?$orderby=IssueValue asc,StatusValue desc&$filter="+dropValue+" eq '"+secondFilterVal+"'&groupby=IssueValue/StatusValue
一切正常,除了一种情况。有时,SecondFilterVal 的值是带有撇号的“Manager's Bulletins”。当我调用电话时,我收到一条错误的请求消息。我在这里能做什么?不幸的是,“经理公告”文本无法更改。我正在考虑使用“$filter=substringof.....”,但它与其他所有东西一起工作得很好。谢谢!
最佳答案
感谢@Lauri 和@charlietfl 的评论。 @charlietfl 给我的信息特别有用,因为它让我看到了不同的选项,而encodeURIComponent() 就是正确的选择。阅读 MDN encodeURIComponent()这个很棒的链接到 REST Filters使用上面的代码帮助我解决了我的问题:
出于某种奇怪的原因,您需要撇号两次:结果 Manager%27%27s%20Bulletins
工作完美。
var str = fixedEncodeURIComponent("Manager's Bulletins");
function fixedEncodeURIComponent(src) {
return encodeURIComponent(src).replace(/[!'()*]/g, function (c) {
return '%' + c.charCodeAt(0).toString(16) + '%' + c.charCodeAt(0).toString(16);
});
}
关于javascript - 使用包含撇号的值进行 REST 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32213772/