- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 DevOps Restapi 来获取一些信息。POST 方法对我来说效果很好。
我想更新我的工作项目的状态。为此,我需要使用 PATCH 方法。这不起作用,并且没有给出任何类型的错误。
function postApiData(ApiUrl, responseBody) {
var res = '';
try {
$.ajax({
type: 'POST',
async: false,
url: ApiUrl,
contentType: 'application/json',
data: JSON.stringify(responseBody),
cache: false,
dataType: 'json',
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("" + ":" + _token));
},
}).done(function (data) {
res = data;
}).fail(function (e) {
});
} catch (error) {
var x = error;
throw x;
}
return res;
};
对于 Patch 方法,我正在修改一些内容。但它没有给出任何不更新我的工作项目的错误。我还检查了我的 token 访问权限。我拥有完全访问权限。
type: 'PATCH',
contentType: 'application/json-patch+json',
最佳答案
我在 Ajax 中使用 PATCH
编写了一个简单的示例:
<script type="text/javascript">
$(document).ready(function () {
$("#SelectWIT").on("click", function () {
var json= [{
"op": "add",
"path": "/fields/System.State",
"value": "Closed"
}];
$.ajax({
type: 'PATCH',
url: 'https://dev.azure.com/{org name}/_apis/wit/workitems/{WIT id}?api-version=5.1',
contentType: 'application/json-patch+json',
data: JSON.stringify(json),
cache: false,
dataType: 'application/json-patch+json',
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("" + ":" + "{PAT token}"));
},
}).error(function (e) {
var s = "error error error";
});
})
});
</script>
注意:不仅contentType
需要设置为application/json-patch+json
,而且dataType<也需要设置为
.application/json-patch+json
/
我使用Fiddler来捕获这个操作:
您可以看到工作项状态已成功更新。
更新:
关于javascript - 开发运营 REST API : can not update work item status using PATCH method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59179390/
SpruceMail 是一款 SaaS 产品,可帮助公司发布赚钱的 Facebook 广告。产品的价值定位很简单:Facebook 广告是复杂的。你要折腾很多事情,可能很快几千美元就花掉了却回报
别人的成功经验抄不来,但是别人遇到的坑我们可以躲。能够躲过越多的坑离目标就越近。 别人的成功经验抄不来,但是别人遇到的坑我们可以躲。能够躲过越多的坑离目标就越近。本人虽然进入互联网行业
我是一名优秀的程序员,十分优秀!