Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.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 SharePoint 2010 Rest API错误(未检索数据)_Javascript_Rest_Sharepoint 2010 - Fatal编程技术网

Javascript SharePoint 2010 Rest API错误(未检索数据)

Javascript SharePoint 2010 Rest API错误(未检索数据),javascript,rest,sharepoint-2010,Javascript,Rest,Sharepoint 2010,运行下面的代码时,出现以下错误: 无法获取未定义或空引用的属性“结果” 你不用休息 如果要使用REST,则需要以下URI: 您的代码示例可以使用REST API重写,如下所示: (function() { var url = "http://my.sharepoint.com/demo/_api/web/lists/GetByTitle('IceCreamTrucks')/items?$select=State"; $.ajax({ url:url,

运行下面的代码时,出现以下错误: 无法获取未定义或空引用的属性“结果”

你不用休息

如果要使用REST,则需要以下URI:

您的代码示例可以使用REST API重写,如下所示:

(function() {
    var url = "http://my.sharepoint.com/demo/_api/web/lists/GetByTitle('IceCreamTrucks')/items?$select=State";
    $.ajax({
        url:url,
        type:"GET",
        dataType:"json",
        headers: {"Accept": "application/json; odata=verbose"},
        success: function(data) {
            console.log(data);
        },
        error: function(data) {
            console.log(data);
        }
    })
}());

由于在
success
回调中您已经获得
结果
对象,因此发生此错误:

success(data.d)  //<-- data.d returns results object
关于这一点:

function success(results)
{
     console.log(results);
}

您还可以考虑在使用SharePoint 2010 REST API时使用。以下示例演示了如何使用获取列表项:

OData.read({
requestUri:_spPageContextInfo.webAbsoluteUrl+“/_vti_bin/listdata.svc/IceCreamTrucks?$select=State”,
enableJsonpCallback:true
}, 
功能(数据){
对于(var i=0;i
我得到[object]嗨!我被授权了。我该怎么办?
function success(data)
{
    console.log(data.d.results);
}
function success(results)
{
     console.log(results);
}
OData.read({ 
    requestUri: _spPageContextInfo.webAbsoluteUrl + "/_vti_bin/listdata.svc/IceCreamTrucks?$select=State", 
    enableJsonpCallback: true
   }, 
   function (data) {
       for(var i =0; i < data.results.length; i++) {
           console.log(data.results[i].State);  
       } 
   }, 
   function (err) {
      // error function.
});