javascript 如何从共享点列表中检索 json 对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13878001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to retrieve a json object from a sharepoint list
提问by Jamie Hutber
I am created myself a custom list with sharepoint 2007, which is exactly the same as any excel spreadsheet in effect.
我自己创建了一个带有 sharepoint 2007 的自定义列表,它与任何有效的 Excel 电子表格完全相同。
I was told that i can get this out all of the information as a json or XML object. I don't have access to the file system, only to sharepoint web interface.
有人告诉我,我可以将所有信息作为 json 或 XML 对象获取。我无权访问文件系统,只能访问 sharepoint Web 界面。
Can i just use a url and do my normal getJson
?
我可以只使用一个 url 并做我的正常getJson
吗?
$.getJSON("http://somesharepointurl.asp?get=json",function(results){
console.info(results);
$.each(results, function(){
});
});
Or is there no way of doing this without writing some backend service?
或者没有编写一些后端服务就没有办法做到这一点?
Edit
编辑
https://someserver/sites/DisasterRecovery/eventmgmt/DRR/_vti_bin/owssvr.dll?Cmd=Display&List={B0ACA997-8A41-498B-97FE-B276D48F64D7}&XMLDATA=TRUE
I have tried this... it gave me this:
我试过这个......它给了我这个:
HTTP/1.1 200 OK
Server: Microsoft-IIS/7.5
Date: Fri, 14 Dec 2012 11:41:55 GMT
Connection: close
No idea what to look for whatsoever i'm afraid :(
不知道要找什么,我害怕:(
回答by Alexey
- SharePoint 2007 doesn't provide you with JSON formatted results, only SOAP/XML web services and the URL Protocol you refer to in the update
- Make sure you append the /_vti_bin part to the address of the correct subsite, rather than the library (although if you made this error, you'd get 404)
- SharePoint 2007 不向您提供 JSON 格式的结果,仅提供 SOAP/XML Web 服务和您在更新中引用的 URL 协议
- 确保将 /_vti_bin 部分附加到正确子站点的地址,而不是库的地址(尽管如果犯了这个错误,你会得到 404)
回答by Jamie Hutber
Found the simple answer:
找到了简单的答案:
you will need jQuery 1.4.2+ to run this but its fantastic :) It has many more method's than just getting XML or json back.
你将需要 jQuery 1.4.2+ 来运行它,但它太棒了 :) 它有更多的方法,而不仅仅是让 XML 或 json 回来。
var query = "<Query><OrderBy><FieldRef Name='Created' Ascending='False' /></OrderBy</Query>";
$().SPServices({
operation:"GetListItems",
async:false,
listName:"Home Page Carousel",
CAMLViewFields:"<ViewFields><FieldRef Name='userName'/><FieldRef Name='userDepartment'/><FieldRef Name='message'/></ViewFields>",
CAMLQuery:query,
CAMLRowLimit:10,
completefunc:function (xData, Status) {
console.info(xData);
console.info(Status);
$(xData.responseXML).SPFilterNode("z:row").each(function () {
var $this = $(this);
$this.attr("ows_message")//retrieve list data here and do stuff here
});
}
});
This will return you a lovely chunk of XML .
这将返回一个可爱的 XML 块。
回答by Shawn
Another option, in sharepoint 2010 try use the OData like these : http://webname/_vti_bin/ListData.svc/listname
, and the feature of filter and sort is same as standard OData, refference can be found here: http://www.odata.org/documentation
另一种选择,在 sharepoint 2010 中尝试使用这样的 OData : http://webname/_vti_bin/ListData.svc/listname
,并且过滤和排序的功能与标准 OData 相同,参考可以在这里找到:http://www.odata.org/documentation
回答by Alexey
Try to add &Query=* to the URL query string
尝试在 URL 查询字符串中添加 &Query=*