Tuesday, November 13, 2012
Call WebService using Javascript
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery.SPServices-0.6.1.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function()
{
});
//****************** Create a list item *******************//
function CreateNewItem()
{
var title=document.getElementById("txtTitle").value;
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>TestList</listName> \
<updates> \
" + batch + "</updates> \
</UpdateListItems> \
</soap:Body> \
</soap:Envelope>";
$.ajax({
url: "http://sharepoint.server/sites/yoursite/_vti_bin/lists.asmx",
beforeSend: function(xhr) {
xhr.setRequestHeader("SOAPAction",
"http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
},
type: "POST",
dataType: "xml",
data: soapEnv,
complete: Result,
contentType: "text/xml; charset=utf-8"
});
}
function Result(xData, status)
{
}
</script>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment