0

我在使用 SP 服务从子站点获取用户信息时遇到问题。使用下面的代码我得到了错误There are multiple root elements.

var employeeName = $(this).attr('ows_Employee');
var employeeInfoViewFields = '<ViewFields>\
                                <FieldRef Name="Title" />\
                                <FieldRef Name="Department" />\
                                <FieldRef Name="JobTitle" />\
                              </ViewFields>\
                              <Where>\
                                <Eq>\
                                  <FieldRef Name="Title" />\
                                  <Value Type="Text">' + employeeName + '</Value>\
                                </Eq>\
                              </Where>';
$().SPServices({
  operation: 'GetListItems',
  async: false,
  listName: 'UserInfo',
  // listName: 'User Information List',
  CAMLViewFields: employeeInfoViewFields,
  completefunc: function(xData, Status) {
    // Do stuff
  }
});
4

1 回答 1

0

我最终用标准的 ajax 调用替换了 SPServices。这完美地工作。

$.ajax({
  url: "/_api/lists/getbytitle('User Information List')/items?$filter=Title eq '" + employeeName + "'&$select=Department,JobTitle",
  type: "GET",
  async: false,
  success: function (xml) {
    department = $(xml).find('d\\:Department, Department').text();
    jobTitle = $(xml).find('d\\:JobTitle, JobTitle').text();
  },
  error: function (a, b, c) {
    alert(c);
  }
});
于 2016-05-24T18:58:38.980 回答