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 ...
Get Applied ASP.NET 4 in Context now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.