Consider this as my code for displaying Announcements list in a site page on my SharePoint 2010 site:
<html>
<head>
<script type="text/javascript" src="/Test_Library/js/jquery-1.9.1.min.js"></script>
<!-- <script type="text/javascript" src="http://mvms172:9999/Test_Library/js/jquery.SPServices-2014.02.min.js"> --></script>
<script type="text/javascript" src="/Test_Library/js/jquery.SPServices-2014.02.js"></script>
</head>
<body>
<table id="Announcements" border=1 width="90%" align="center">
<tr align='left'>
<td><strong>_Title</strong></td>
<td><strong>_Dream_x0020_Destination</strong></td>
<td><strong>_PPP</strong></td>
</tr>
</table>
<SCRIPT type=text/javascript>
$(document).ready(function() {
getMyListData() ;
function getMyListData()
{
var method = "GetListItems";
var list = "Announcements";
var fieldsToRead = "<ViewFields>" + "<FieldRef Name='Title' />" + "<FieldRef Name='Dream_x0020_Destination' />" + "<FieldRef Name='PPP' />" + "</ViewFields>";
var query = "<Query>" + "<Where>" + "<Or>" + "<Or>" + "<Eq>" + "<FieldRef Name='Title'/><Value Type='Text'>The America</Value>" + "</Eq>" + "<Eq>" + "<FieldRef Name='Dream_x0020_Destination' /><Value Type='Text'>USA</Value>" + "</Eq>" + "</Or>" + "<IsNotNull>" + "<FieldRef Name='PPP'/>" + "</IsNotNull>" + "</Or>" + "</Where>" + "<OrderBy>" + "<FieldRef Name='PPP' Ascending='False'/>" + "</OrderBy>" + "</Query>";
$().SPServices
({
operation: method,
async: false,
listName: list,
CAMLViewFields: fieldsToRead,
CAMLQuery: query,
completefunc: function (xData, Status)
{
$(xData.responseXML).SPFilterNode("z:row").each(function()
{
var _Title = $(this).attr("ows_Title");
var _Dream_x0020_Destination = $(this).attr("ows_Dream_x0020_Destination");
var _PPP = $(this).attr("ows_PPP");
$("#Announcements").append("<tr align='middle'>" +
"<td align='left'>"+_Title+"</td>" +
"<td align='left'>"+_Dream_x0020_Destination+"</td>" +
"<td align='left'>"+_PPP+"</td>" +
"</tr>");
});
}
});
};
});
</script>
</body>
</html>
Here is my CAMLQuery Builder generated Query as requested by @Nadeem :
string sQuery = @"<Query><Where><Or><Or><Eq><FieldRef Name=""Title""/><Value Type=""Text""></Value></Eq><Eq><FieldRef Name=""Dream_x0020_Destination"" /><Value Type=""Text""></Value></Eq></Or><IsNotNull><FieldRef Name=""PPP""/></IsNotNull></Or></Where><OrderBy><FieldRef Name=""PPP"" Ascending=""False""/></OrderBy></Query>";
string sViewFields = @"<FieldRef Name=""Title"" /><FieldRef Name=""Dream_x0020_Destination"" /><FieldRef Name=""PPP"" />";
string sViewAttrs = @"Scope=""Recursive""";
uint iRowLimit = 0;
var oQuery = new SPQuery();
oQuery.Query = sQuery;
oQuery.ViewFields = sViewFields;
oQuery.ViewAttributes = sViewAttrs;
oQuery.RowLimit = iRowLimit;
SPListItemCollection collListItems = oList.GetItems(oQuery);
foreach (SPListItem oListItem in collListItems)
{
}
I have created a CEWP in this site page and uploaded all my related JS and txt files in a manually created document library. I want to retrieve and display all the rows that contains data in Announcements List in a tabular format inside this CEWP created on this site page. Problem: I was able to see only hard-coded HTML content (i.e. a single row that is in body tag and td for which is already written) and none other actual rows from my Announcements List.
Following is the Error I can find by Inspect Element on Chrome Browser:
- XMLHttpRequest cannot load http://mvms172:99999999/_vti_bin/Lists.asmx. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.send @ jquery-1.9.1.min.js:19
- Uncaught TypeError: Cannot read property 'parentElement' of null
In the above para, the Error description, the link is incorrect (Look at the number of 9's. This is actually not allowing me to use list operations). The correct link is "http://mvms172:9999/_vti_bin/Lists.asmx". How do I correct this?
NOTE: I am new to SharePoint and would like a few pointers/feedback to why this is not working
Edit:
- Refer Answer by @Thriggle if you don't wish to use SPServices and jQuery (or if you want to use JavaScript Client Object Model)
- Refer Answer by @Yash Saraiya if you want a solution using SPServices and jQuery.
Both these solutions are working absolutely fine.
Eq
operator. Something like<Value Type="Text">XYZ</Value>