Using Javasctipt Script getting sharepoint list data
This technique is called client object model using ECMA script
We can also get list data using web-service
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
this.list = web.get_lists().getByTitle("ListName");
clientContext.load(list, 'Title', 'Id');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onListLoadSuccess),
Function.createDelegate(this, this.onQueryFailed));
}
function onListLoadSuccess(sender, args) {
alert("List title : " + this.list.get_title() + "; List ID : "+ this.list.get_id());
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
This technique is called client object model using ECMA script
We can also get list data using web-service
$(document).ready(function()
{
var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
<soapenv:Body>
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>
<listName>ListName</listName>
<viewFields>
<ViewFields>
<FieldRef Name='Title' />
</ViewFields>
</viewFields>
</GetListItems>
</soapenv:Body>
</soapenv:Envelope>";
$.ajax({
url: "http://my_site/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset="utf-8""
});
});
function processResult(xData, status) {
$(xData.responseXML).find("z\:row").each(function() {
alert($(this).attr("ows_Title"));
});
}
Does the above code work for MOSS 2007?
ReplyDeleteYes john of course it works
ReplyDeleteExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
ReplyDeletehere what is sp.js