TAILIEUCHUNG - ASP.NET AJAX Programmer’s Reference - Chapter 15

Proxy Classes Chương trước đã cung cấp cho bạn chuyên sâu trong phạm vi bảo hiểm của cơ sở hạ tầng REST của AJAX gọi phương thức xử lý yêu cầu. Chương này cho bạn thấy như thế nào cơ sở hạ tầng này ẩn phức tạp của nó phía sau các lớp proxy để cho phép bạn để chương trình chống lại một đối tượng từ xa như bạn sẽ chống lại một đối tượng địa phương. Proxy là gì Dù sao? Chúng ta hãy xem xét lại các chức năng JavaScript thêm được hiển thị trong Liệt kê 14-14. | c Proxy Classes The previous chapter provided you with in-depth coverage of the AJAX REST method call request processing infrastructure. This chapter shows you how this infrastructure hides its complexity behind proxy classes to enable you to program against a remote object as you would against a local object. What s a Proxy Anyway Let s revisit the add JavaScript function shown in Listing 14-14 of Chapter 14 and shown again here in Listing 15-1. This JavaScript function was registered as the event handler for the Add button s click event of in Listing 14-14. Listing 15-1 The add Method function add var servicePath http localhost AJAXEnabledFuturesWebSite2 var methodName Add var useGet false var xValue get firstNumber .value var yValue get secondNumber .value var params x xValue y yValue var userContext get result var webServiceProxy new 0 request servicePath methodName useGet params onSuccess onFailure usercontext Now here is a question for you How would you code this add method if the Math class see Listing 14-15 were a local class in your client-side code such as the local class shown in Listing 15-2 Chapter 15 Proxy Classes Listing 15-2 A Local Class with the Same Name and Methods as the Remote Web Service MyNamespace function Add function x y return x y Wouldn t your implementation of the add method be something like the one shown in Listing 15-3 Listing 15-3 Implementation of add Method if the Web Service Class Were a Local Class function add var math new var xValue get firstNumber .value var yValue get secondNumber .value var z xValue yValue get result .innerText z As you can see in this listing if the Math object were a local object you would directly invoke the Add method on the .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.