Geeks With Blogs
Wayne Magnum's Blog
<div>
    <p>
        Task Title: 
        <input id="Text1" type="text" />
        <input id="Button1" type="button" value="Create Task" />
    </p>
    </div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  
<script>
    $(document).ready(function () {
        $("#newTaskButton").click(function () {
            CreateNewItem($("#newTaskTitle").val());
        });
    });


    function CreateNewItem(title) {
        var batch =
    "<Batch OnError=\"Continue\"> \
        <Method ID=\"1\" Cmd=\"New\"> \
            <Field Name=\"Title\">" + title + "</Field> \
        </Method> \
    </Batch>";

        var soapEnv =
    "<?xml version=\"1.0\" encoding=\"utf-8\"?> \
    <soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \
        xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \
        xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> \
        <soap:Body> \
        <UpdateListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"> \
            <listName>Tasks</listName> \
            <updates> \
            " + batch + "</updates> \
        </UpdateListItems> \
        </soap:Body> \
    </soap:Envelope>";

        var wsUrl = window.location.protocol + "//" + window.location.hostname + L_Menu_BaseUrl + "/_vti_bin/lists.asmx";
        $.ajax({
            url: wsUrl,
            beforeSend: function (xhr) {
                xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
            },
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=utf-8"
        });
    }

    function processResult(xData, status) {
        alert(status);
    }
</script>
Posted on Monday, July 23, 2012 12:52 PM | Back to top


Comments on this post: JQuery Add New Item to SPList

# re: JQuery Add New Item to SPList
Requesting Gravatar...
Thanks for sharing this code of splist but tell me for SPList completely, what the use of this and where we can use
Left by Eye Cataracts on Jul 24, 2012 6:33 AM

# re: JQuery Add New Item to SPList
Requesting Gravatar...
This is informative, but as Eve says where can we use it?. What is the sense of code without explanation?
Left by Reputation Advocate on Apr 12, 2013 5:50 AM

# re: JQuery Add New Item to SPList
Requesting Gravatar...
Its an alternative example of how to use JQuery to interact with SharePoint.
Left by Wayne Magnum on Apr 12, 2013 10:15 AM

Your comment:
 (will show your gravatar)


Copyright © Wayne H Magnum | Powered by: GeeksWithBlogs.net | Join free