[英]Getting list data from SharePoint 2010 site using Jquery
I am trying to get list data from sharepoint site using JQuery, but have got nothing returned yet, no errors in firebug either.我正在尝试使用 JQuery 从 sharepoint 站点获取列表数据,但还没有返回任何内容,firebug 中也没有错误。 Any clue what is wrong?
任何线索有什么问题?
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(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>Action Items</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() {
console.log("aaaa");
var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
$("#tasksUL").append(liHtml);
});
}
Right after your line就在你排队之后
function processResult(xData, status) {
add an alert like this:添加这样的警报:
alert(xData.responseText);
That will show you what is coming back from the call to GetListItems.这将向您展示调用 GetListItems 后返回的内容。
also, you should change this line:另外,您应该更改此行:
$(xData.responseXML).find("z\\:row").
to this:对此:
$(xData.responseXML).find("[nodeName='z:row']")
which is more reliable across browsers.这在浏览器中更可靠。 (See my blog post: http://sympmarc.com/2009/11/08/sharepoints-web-services-jquery-and-the-zrow-namespace-in-safari-and-chrome/ )
(见我的博文: http://sympmarc.com/2009/11/08/sharepoints-web-services-jquery-and-the-zrow-namespace-in-safari-and-chrome/ )
As Rob Windsor mentions in his answer, I've got many of the SharePoint Web Services wrapped with jQuery to make them easier to use in my SPServices jQuery library . As Rob Windsor mentions in his answer, I've got many of the SharePoint Web Services wrapped with jQuery to make them easier to use in my SPServices jQuery library . I'd suggest you try it out, as you won't have to do as much work.
我建议您尝试一下,因为您不必做太多工作。
I strongly suggest that you use the client object model instead of the Web services.我强烈建议您使用客户端 object model 而不是 Web 服务。 Much richer functionality and much, much easier to use.
更丰富的功能,更容易使用。
The Client Object Model and jQuery客户端 Object Model 和 jQuery
If you really want to use the Web services, then I suggest you check out the SPServices project .如果您真的想使用 Web 服务,那么我建议您查看SPServices 项目。
You should handle the ajax success
event, not the complete event.您应该处理 ajax
success
事件,而不是完成事件。 The complete event doesn't have that signature.完整的事件没有那个签名。
http://api.jquery.com/jQuery.ajax/ http://api.jquery.com/jQuery.ajax/
complete(jqXHR, textStatus)完成(jqXHR,文本状态)
success(data, textStatus, jqXHR)成功(数据,文本状态,jqXHR)
Perhaps you have a same-origin policy violation.也许您违反了同源策略。
Check that the current url where runs the script, begins with http://my_site/
检查运行脚本的当前 url 是否以
http://my_site/
开头
Hope this helps.希望这可以帮助。 Cheers
干杯
Put the processResult
function within $(documnet).ready
and check将
processResult
function 放入$(documnet).ready
并检查
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.