2017-08-09 52 views
2

我有一個網站託管在一個自定義HTML表單的Apache網絡服務器上。我也有一個Sharepoint 2013列表(在同一網絡上),我需要自定義HTML表單來添加項目。到目前爲止,我一直在研究JS的JS(特別是sp.js等)。通過Apache Web服務器通過Javascript創建Sharepoint 2013列表項目

我也看過在Sharepoint本身上託管窗體,因爲它看起來像sp.js期望有一個相對的url,這對Apache服務器沒有任何意義,所以更成功。

JS代碼到目前爲止

function save(){ 
    if(confirm("Are you sure you want to submit this?")){ 
    ExecuteOrDelayUntilScriptLoaded(createListItem, "sp.js"); 
    } 

} 




function createListItem() { 
    var siteUrl= "/sites/mysites/site"; 
    var clientContext = new SP.ClientContext(siteUrl); 
    var oList = clientContext.get_web().get_lists().getByTitle('Sandbox'); 

    var itemCreateInfo = new SP.ListItemCreationInformation(); 
    this.oListItem = oList.addItem(itemCreateInfo); 
    oListItem.set_item('Title', 'My New Item!'); 
    oListItem.set_item('Line Type', 'Type 1'); 
    oListItem.set_item('Amount', '100'); 
    oListItem.update(); 

    clientContext.load(oListItem); 
    clientContext.executeQueryAsync(
     Function.createDelegate(this, this.onQuerySucceeded), 
     Function.createDelegate(this, this.onQueryFailed) 
    ); 
} 

function onQuerySucceeded() { 
    alert('Item created: ' + oListItem.get_id()); 
} 

function onQueryFailed(sender, args) { 
    alert('Request failed. ' + args.get_message() + 
     '\n' + args.get_stackTrace()); 
} 

HTML頭

<head> 
    <script src="http://mysite/sites/site/_layouts/1033/init.js" type="text/javascript"></script> 
    <script src="http://mysite/sites/site/_layouts/MicrosoftAjax.js" type="text/javascript"></script> 
    <script src="http://mysite/sites/site/_layouts/sp.core.js" type="text/javascript"></script> 
    <script src="http://mysite/sites/site/_layouts/sp.runtime.js" type="text/javascript"></script> 
    <script src="http://mysite/sites/site/_layouts/sp.js" type="text/javascript"></script> 
    <script src="TER.js"></script> 
    </head> 

注意的是,在我的Javascript改變變量SITEURL需要取決於哪個虛擬主機提供商,我目前正在測試上(即絕對或相對)。

有沒有人知道我試圖做甚至可能或者我需要嘗試不同的方法?

回答

0

您可以使用https://aymkdn.github.io/SharepointPlus/http://sympmarc.github.io/SPServices/與使用Javascript和AJAX的Sharepoint列表和庫進行交互。

與CORS相關,它更容易直接在Sharepoint上託管自定義HTML表單。我通過在Sharepoint文檔庫中託管我的HTML表單和JS文件來使用此方法。

用我最喜歡的SharepointPlus,你可以添加一個列表項有:

$SP().list("ListName", "http://path/to/sharepoint/site/collection").add({ Title: "foobar" }); 

親切的問候

+0

託管在Apache的HTML與XMLHttpRequest來進口形式到SharePoint(必須允許在CORS Apache服務器),以及SharepointPlus做了訣竅。謝謝。 – thetechnician94

相關問題