[英]SPServices update list item not updating
I am learning sharepoint 2013 and trying to add items from web part. 我正在学习sharepoint 2013,并尝试从Web部件添加项目。 Below is my code.
下面是我的代码。 After I click submit button no error is shown but no item is added to the list.
单击提交按钮后,未显示任何错误,但没有任何项目添加到列表中。 I have been trying my whole day to find out what is the problem but I could not figure it out.
我整天都在尝试找出问题所在,但无法解决。 Please help.
请帮忙。
<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>
If you are learning SharePoint 2013, I would recommend learning to do this with the JavaScript APIs first instead of relying on 3rd party tools that may or may not work correctly. 如果您正在学习SharePoint 2013,我建议您先学习使用JavaScript API来做到这一点,而不要依赖于可能无法正常工作的第三方工具。
Here is a link to some basic list operations using the CSOM from MSDN https://code.msdn.microsoft.com/SharePoint-2013-Perform-eba8df54 这是从MSDN https://code.msdn.microsoft.com/SharePoint-2013-Perform-eba8df54使用CSOM到一些基本列表操作的链接
maybe my answer can help you: 也许我的回答可以帮助您:
<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());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.