Skip to content

Instantly share code, notes, and snippets.

@cacheleocode
Created August 22, 2012 17:13
Show Gist options
  • Save cacheleocode/3427640 to your computer and use it in GitHub Desktop.
Save cacheleocode/3427640 to your computer and use it in GitHub Desktop.
jQuery AJAX reading data from SharePoint 2010 list
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>list</title>
<script type="text/javascript" src="/scripts/jquery.js"></script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){
var soapEnv =
"<?xml version=\"1.0\" encoding=\"utf-8\"?> \
<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"> \
<soapenv:Body> \
<GetListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"> \
<listName>products</listName> \
<viewFields> \
<ViewFields xmlns=\"\"> \
<FieldRef Name=\"Name\" /> \
</ViewFields> \
</viewFields> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";
$.ajax({
url: "/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\"",
error: function(XMLHttpRequest, textStatus, errorThrown){
console.debug(errorThrown);
},
success: function(data){
console.debug(data);
}
});
}); // ready
function processResult(xData, status)
{
$('#WSResponse').text(status);
$(xData.responseXML).find("z\\:row").each(function() {
var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
$("#tasksUL").append(liHtml);
});
}
//]]>
</script>
</head>
<body>
<ul id="tasksUL"/>
<div id="WSResponse"/>
</body>
</html>
@iceshine34
Copy link

In line 45,It works when I change responseXML to responseText.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment