Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过javascript从tfs获取工作项_Javascript_Powershell_Tfs - Fatal编程技术网

通过javascript从tfs获取工作项

通过javascript从tfs获取工作项,javascript,powershell,tfs,Javascript,Powershell,Tfs,我在通过以下javascript代码从tfs获取工作项时遇到一些问题: var res = new XMLHttpRequest(); var body = "{'query' : \"select * from workitems where [Change Number] = 'CH-0000433' \"}" ; res.open("POST","<SERVER_NAME>/tfs/InternalApplications/Testing%20Services/_apis/

我在通过以下javascript代码从tfs获取工作项时遇到一些问题:

var res = new XMLHttpRequest();

var body = "{'query' : \"select * from workitems where [Change Number] = 'CH-0000433' \"}" ;

res.open("POST","<SERVER_NAME>/tfs/InternalApplications/Testing%20Services/_apis/wit/wiql?api-version=1.0",true,<LOGIN>,<PASSWORD>);

res.setRequestHeader('Content-type', 'application/json');

res.send(body);
var res=new-XMLHttpRequest();
var body=“{'query':\”从工作项中选择*,其中[Change Number]=“CH-0000433'\”;
res.open(“POST”,“/tfs/InternalApplications/Testing%20Services/_api/wit/wiql?api version=1.0”,true,,);
res.setRequestHeader('Content-type','application/json');
决议(正文);
当我试图执行这个脚本时,我得到了401-Unauthorized错误

我已经编写了类似于此脚本的PowerShell,它运行良好:

$q2 = """select Id from workitems where [Change Number] = 'CH-0000433' """

$res = Invoke-WebRequest <Server_Name>/tfs/InternalApplications/Testing%20Services/_apis/wit/wiql?api-version=1.0 `
-ContentType application/json `
-Credential $(Get-Credential) `
-Method Post `
-Body "{'query' : $q2}" `
-UseBasicParsing
$q2=”““从工作项中选择Id,其中[更改编号]='CH-0000433'”
$res=Invoke WebRequest/tfs/InternalApplications/Testing%20Services/_api/wit/wiql?api版本=1.0`
-ContentType应用程序/json`
-凭证$(获取凭证)`
-路标`
-正文“{'query':$q2}”`
-UseBasicParsing

我想在javascript的情况下,我传递的凭据是错误的,那么我应该如何更改它呢

我使用下面的代码片段在TFS 2017上进行了测试,它正在工作:

var jsonObj = [{
                "op": "add",
                "path": "/fields/System.Title",
                "value": "cecetest1"
            }];

            $.ajax({
                url: 'http://TFS2017:8080/tfs/DefaultCollection/ScrumProject/_apis/wit/workitems/$Task?api-version=1.0',
                type: 'PATCH',
                contentType: "application/json-patch+json",
                data: JSON.stringify(jsonObj),
                cache: false,
                dataType: 'json',
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Authorization", "Basic " + btoa("domain\\username" + ":" + "password"));
                },
            })

是的,我有,但它不起作用((@gvee-当然,在创建此帖子之前,我试图从stackoverflow.com/questions/36072327/实现解决方案,但在我的案例中失败))