O'Reilly logo

Applied ASP.NET 4 in Context by Adam Freeman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Ajax to POST to a Web Service

Although you can POST data to a web page, a small amount of additional work will let us post to a WCF web service method. In this section, we'll add a method to our web service that will perform the calculation and revise our jQuery script. Listing 11-19 shows the addition to the TriathlonService.svc code-behind class.

Listing 11-19. Adding a calculation method to the web service

[OperationContract] [WebInvoke] public JSONCalculationResult PerformCalculation(int laps, int length, int mins, int cals) {     const float metersToMiles = 0.00062137119223733f;     const float minsPerHour = 60f;     return new JSONCalculationResult() {         distance = ((laps * length) * metersToMiles).ToString("F2"),         calories ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required