HTML and CSS Reference
In-Depth Information
Detailed discussion of all the jQuery Ajax techniques listed in Table 2-7 is beyond the scope of this
book. The examples that follow illustrate the use of the $.ajax() function because it's the mother of all the
other techniques.
The examples in this section show how you can use $.ajax() in Web Forms as well as MVC
applications. Both of the applications you develop display a simple web page, as shown in Figure 2-9.
Figure 2-9. Web page to convert a temperature between Celsius and Fahrenheit
The web page allows you to enter a temperature value in Celsius or Fahrenheit and converts it to the
other scale. The temperature conversion happens in a WCF service for the Web Forms application and in a
controller action method for the MVC application.
Using the jQuery $.ajax() Method in a Web Forms Application
The WCF service that converts temperature values between Celsius and Fahrenheit is shown in Listing
2-15.
Listing 2-15. WCF Service for Converting Temperature Values
namespace AjaxWebForm
{
[DataContract]
public class TemperatureData
{
[DataMember]
public decimal Value { get; set; }
[DataMember]
public string Unit { get; set; }
}
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
 
Search WWH ::




Custom Search