【发布时间】: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