SPServices update list item not updating

1.1k Views Asked by At

I am learning sharepoint 2013 and trying to add items from web part. 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>
2

There are 2 best solutions below

0
On

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.

Here is a link to some basic list operations using the CSOM from MSDN https://code.msdn.microsoft.com/SharePoint-2013-Perform-eba8df54

0
On

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());
    }