2016-09-27 154 views
3

这里我试图让reccurring从日历列表中的事件SharePoint Online的应用程序,并有正在使用的代码像
获得的XMLHttpRequest无法加载(URL)的预检响应是(重定向)

hostWebUrl = decodeURIComponent(manageQueryStringParameter('SPHostUrl')); 
    function GetListData() { 
     var webUrl = hostWebUrl;// = "http://server/sitewhereyourlistexists"; 
     var listGuid = "{2000da75-8663-42d9-9999-ad855c54b4e0}" 


     // An XMLHttpRequest object is used to access the web service 
     var xhr = new XMLHttpRequest(); 
     var url = webUrl + "/_vti_bin/Lists.asmx"; 
     xhr.open("POST", url, true); 
     xhr.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); 
     xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems"); 

     // The message body consists of an XML document 
     // with SOAP elements corresponding to the GetListItems method parameters 
     // i.e. listName, query, and queryOptions 
     var data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
      "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + 
       "<soap:Body>" + 
       "<GetListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">" + 
         "<listName>" + listGuid + "</listName>" + 
         "<query>" + 
          "<Query><Where>" + 
           "<DateRangesOverlap>" + 
            "<FieldRef Name=\"EventDate\"/>" + 
            "<FieldRef Name=\"EndDate\"/>" + 
            "<FieldRef Name=\"RecurrenceID\"/>" + 
            "<Value Type=\"DateTime\"><Today/></Value>" + 
           "</DateRangesOverlap>" + 
          "</Where></Query>" + 
         "</query>" + 
         "<queryOptions>" + 
          "<QueryOptions>" + 
           "<ExpandRecurrence>TRUE</ExpandRecurrence>" + 
          "</QueryOptions>" + 
         "</queryOptions>" + 
       "</GetListItems>" + 
       "</soap:Body>" + 
      "</soap:Envelope>"; 

     // Here we define what code we want to run upon successfully getting the results 
     xhr.onreadystatechange = function() { 
      if (xhr.readyState == 4) { 
       if (xhr.status == 200) { 
        var doc = xhr.responseXML; 
        // grab all the "row" elements from the XML results 
        var rows = doc.getElementsByTagName("z:row"); 
        var results = "Today's Schedule (" + rows.length + "):\n\n"; 
        var events = {}; 
        for (var i = 0, len = rows.length; i < len; i++) { 
         var id = rows[i].getAttribute("ows_FSObjType"); // prevent duplicates from appearing in results 
         if (!events[id]) { 
          events[id] = true; 
          var allDay = rows[i].getAttribute("ows_fAllDayEvent"), 
           title = rows[i].getAttribute("ows_Title"), 
           start = rows[i].getAttribute("ows_EventDate"); 
          var index = start.indexOf(" "); 
          var date = start.substring(5, index) + "-" + start.substring(2, 4); // get the date in MM-dd-yyyy format 
          start = start.substring(index, index + 6); // get the start time in hh:mm format 
          var end = rows[i].getAttribute("ows_EndDate"); 
          index = end.indexOf(" "); end = end.substring(index, index + 6); // get the end time in hh:mm format 
          results += date + " " + (allDay == "1" ? "All Day\t" : start + " to " + end) + " \t " + title + "\n"; 
         } 
        } 
        alert(results); 
       } else { 
        alert("Error " + xhr.status); 
       } 
      } 
     }; 

     // Finally, we actually kick off the query 
     xhr.send(data); 
    } 


后无效调用这个函数。准备部分不会检索任何数据,但有国家统计局的错误,我可以在浏览器的控制台,是如下
enter image description here

+0

您好,您是否尝试安装Fiddler,然后再次运行POST? Fiddler是一个很棒的网络方法调试工具,你可以看到请求和响应。请在测试后回复,以便我可以进一步提供帮助。 – Daniel

+0

是的,我已经安装了这个现在我该如何调试我的代码呢? – Madhav

+0

你只需要打开应用程序(Fiddler),然后在你的应用程序中执行POST,它将在网络调用 – Daniel

回答

0

,你会点击在左侧面板中的正确的请求看,然后选择“督察“在右侧顶部面板中。然后在不同的请求和响应选项之间进行选择。

Fiddler

+0

okk,所以它应该显示给我,这是导致上述错误? – Madhav

+0

非常多呀 - >别的只是调试你的电话到服务器。请回复你发现的内容,以便我可以进一步提供帮助。 – Daniel

相关问题