如何使用ajax调用通过自定义窗口小部件向工作项添加附件。我了解了有关API调用的信息,但不了解如何实现,通过Ajax,我能够使用我的小部件创建工作项,但无法向其添加附件。在下面找到我的Ajax代码:
$(“#btnAttachment”)。click(function(){
var restURL = "https://dev.azure.com/organizationName/{" + VSS.getWebContext().project.id + "}/_apis/wit/attachments?fileName='C:\Users\Administrator\Downloads\picturemessage_4hm34b3k.kot.png'&api-version=5.0";
var myPatToken = "xyz";
$.ajax({
contentType: 'application/octet-stream',
dataType: 'json',
headers: {
'Authorization': 'Basic ' + btoa("" + ":" + myPatToken)
},
success: function (data) {
alert("Success");
},
error: function (data) {
alert("Failure");
console.log(JSON.stringify(data.responseText));
},
type: 'POST',
url: restURL
});
});