2013年7月5日 星期五

Sitefinity CMS-Part04-使用WCF Webservice

Sitefinity除了提供Library讓使用者開發外,系統還提供wcf webservice。

參考:List of Web Services

以"pagesservice.svc"為例:

網址會回傳json檔,以下實作jquery取得json。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">
function GetJsonData(webserviceUrl, inputJson) {
var res;
$.ajax({
type: "Get"
, url: webserviceUrl
, dataType: "json"
, contentType: "application/json;charset-utf-8"
, async: false
/*, data: inputJson*/
, success: function (response) {
res = response;
}
, error: function () { res = "error"; }
});
return res;
}
$(function () {
var webserviceUrl = "http://localhost/SitefinityCMS/Sitefinity/services/pages/pagesservice.svc/";
var inputJson = "";
var res = GetJsonData(webserviceUrl, inputJson);
$.each(res, function (key, item) {
if (key == "Items") {
$.each(item, function (key2, item2) {
if (key2 == "1") {
var str = "";
$.each(item2, function (key3, item3) {
str = str +"<li>"+ key3 + ":" + item3 + "</li>";
});
var obj = $("#main");
$(str).appendTo(obj);
}
});
}
});
/*var data = $.parseJSON(res);*/
/*alert(data);*/
});
</script>
</head>
<body>
<div id="main"></div>
</body>
</html>

結果:

image

沒有留言:

張貼留言