0
我想創建一個本地代理,它調用一個共享點休息查詢。惱人的Sharepoint REST代理
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string getJson()
{
string listRSSFeedUrl = "http://myurl/_vti_bin/listdata.svc/MyList";
var req = (HttpWebRequest)WebRequest.Create(listRSSFeedUrl);
req.Credentials = CredentialCache.DefaultNetworkCredentials;
req.PreAuthenticate = true;
var res = (HttpWebResponse)req.GetResponse();
var feed = new XmlDocument();
var feedStream = res.GetResponseStream();
feed.Load(feedStream);
return feed.InnerXml;
}
如何返回原始休息查詢應返回的json格式?
jQuery的調用方法如下:
$.ajax({
type: "POST",
url: "SharepointJson.aspx/getJson",
cache: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var markup = "Announcements:<br /><br />";
$.each(data.d.results, function (i, result) {
//Display some properties
markup += 'Title: ' + result.feed + '<br />';
});
//Call the jQuery append method to display the HTML
$('#displayDiv').append($(markup));
}
});