2016-09-27 153 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

相關問題