Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var savedItemID;
- function CreateNewItem(title, listName) {
- 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>" + listName + "</listName> \
- <updates> \
- " + batch + "</updates> \
- </UpdateListItems> \
- </soap:Body> \
- </soap:Envelope>";
- var beforesendArg = function (xhr) {
- xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
- };
- var onsuccessArg = function (data) {
- $(data).find('z\\:row').each(function () {
- savedItemID = $(this).attr('ows_ID');
- });
- };
- var onfailArg = null;
- AjaxCall("POST", siteCollection + "/_vti_bin/lists.asmx", false, soapEnv, "text/xml; charset=utf-8", "xml", beforesendArg, onsuccessArg, onfailArg);
- }
- function AjaxCall(typeArg, urlArg, cacheArg, dataArg, contentTypeArg, datatypeArg, beforesendArg, onsuccessArg, onfailArg) {
- //set a default contenttype if not specified
- if (contentTypeArg === null) {
- contentTypeArg = 'application/x-www-form-urlencoded';
- }
- if (onfailArg === null) {
- onfailArg = function (XMLHttpRequest, textStatus, errorThrown) {
- alert('AjaxCall has failed with the following error message: ' + errorThrown);
- }
- };
- $.ajax({
- type: typeArg,
- cache: cacheArg,
- url: urlArg,
- data: (dataArg),
- contentType: contentTypeArg,
- dataType: datatypeArg,
- beforeSend: beforesendArg,
- success: onsuccessArg,
- error: onfailArg
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement