我正在学习sharepoint 2013并尝试从Web部件添加项目。以下是我的代码。单击“提交”按钮后,不会显示任何错误,但没有项目添加到列表中。我一直在努力寻找问题,但我无法弄明白。请帮忙。
<script src="/ss14/14ss-55555/_layouts/15/l2passets/js/jquery.js" unselectable="on"></script>
<script src="/ss14/14ss-%2055555/_layouts/15/l2passets/js/SPServices.js" unselectable="on"></script>
Email <input name="email" id="email" type="text"><br unselectable="on">
Country<input name="country" id="country" type="text"><br unselectable="on">
<input value="Submit" onclick="addItem()" type="submit">
<script unselectable="on">
var emailVal = $('#email').val();
var countryVal = $('#country').val();
function addItem(){
$().SPServices({
operation: "UpdateListItems",
async: false,
batchCmd: "New",
listName: "Share Point List",
valuepairs: [["Email", emailVal], ["Country", countryVal]],
completefunc: function (xData, Status) {
alert("Data Saved! and Please check your List");
}
});
}
</script>
答案 0 :(得分:0)
如果您正在学习SharePoint 2013,我建议您首先学习使用JavaScript API,而不是依赖可能或可能无法正常工作的第三方工具。
以下是使用MSDN https://code.msdn.microsoft.com/SharePoint-2013-Perform-eba8df54
中的CSOM的一些基本列表操作的链接答案 1 :(得分:0)
也许我的回答可以帮到你:
<input value="Submit" onclick="createListItem()" type="submit">
function createListItem() {//main
var clientContext = new SP.ClientContext('siteUrl');
var oList = clientContext.get_web().get_lists().getByTitle(listName');
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Username', username[1]);
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
alert('Thank you ' + oListItem.get_item('Username') + ' for your registration');
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}