【问题标题】:Creating Sharepoint 2013 List Items via Javascript from Apache webserver从 Apache 网络服务器通过 Javascript 创建 Sharepoint 2013 列表项
【发布时间】:2017-08-10 00:45:41
【问题描述】:

我有一个托管在 Apache 网络服务器上的网站,带有自定义 html 表单。我还有一个 Sharepoint 2013 列表(在同一网络上),我需要自定义 html 表单来添加项目。到目前为止,我一直在研究 SP 的 JSOM(特别是 sp.js 等)。

我还研究了在 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,具体取决于我当前正在测试的网络主机(即绝对或相对)。

有谁知道我正在尝试做的事情是否可行,或者我是否需要尝试不同的方法?

【问题讨论】:

    标签: javascript html sharepoint


    【解决方案1】:

    您可以使用 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" });
    

    亲切的问候

    【讨论】:

    • 使用 XmlHttpRequest 在 Apache 上托管 html 以将表单导入 Sharepoint(必须在 Apache 服务器上允许 CORS),以及 SharepointPlus 就可以了。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2010-11-21
    • 2011-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-10
    • 2017-11-04
    • 1970-01-01
    相关资源
    最近更新 更多