2017-08-09 67 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

相关问题