开发者

Web service returning ajaxified results

开发者 https://www.devze.com 2023-01-16 22:15 出处:网络
I am hoping someone can point me in the right direction here. I am trying to create web service that will return ajaxified results. Specifically, I want to write a web service that will fetch email th

I am hoping someone can point me in the right direction here. I am trying to create web service that will return ajaxified results. Specifically, I want to write a web service that will fetch email through a secure connection. However, rather then have the web service return every single email, I just want to fetch maybe 5 emails at a time. I've always used Ajax as a client helper technology and not sure how t开发者_StackOverflow社区o go about implementing this on a server side, or if its even possible. Can someone please point me to some ideas or some suggestions on how I can accomplish this?

I am using ASP.NET/C#, by the way.


There are a number of ways to return "ajaxified" results (JSON) from a web/wcf services. A WebServices have the attribute [ScriptMethod(ResponseFormat = ResponseFormat.Json)] you can use (and find some examples), WCF services may be configured to return JSON (here is a nice post: http://www.west-wind.com/Weblog/posts/164419.aspx)

But actually I prefer to use ASP.NET MVC to do this. Basically all you need to do in this case is to say return Json(myObject); inside your controller's method.

Here is an example: http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=399 And here is the StackOverflow question about it: ASP.NET MVC controller actions that return JSON or partial html

The returned JSON is standard and can be consumed on the client using any library (jQuery, etc) and in your controller you do all you want and return what you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消