TAILIEUCHUNG - developing facebookbapplications phần 9

Facebook cung cấp một số công cụ mạnh mẽ để làm cho nó dễ dàng hơn để xử lý những trường hợp này Chúng tôi sẽ xem một ví dụ về cách sử dụng những công cụ này ở dụng memcached có thể là một cách tuyệt vời để loại bỏ các truy vấn cơ sở dữ liệu, | Ajax in FBJS 154 That code should look familiar to you. It s the same code we would use for a normal Rails application. Facebooker takes care of hiding the Facebook-specific details from you. We re now using real Ajax to do the same thing we did previously with Mock Ajax. Facebooker made the normal Rails helpers work for us but only in a very simple case. To do much more using Ajax we re going to have to look at the guts of the Facebook Ajax library. Ajax Under the Covers Let s take a look at how Ajax is implemented by Facebook. Facebook provides an Ajax5 object as an interface to the browser s XmlHTTPRequest object. It provides a simple abstraction to your application as you can see in the following code var ajax new Ajax function data do something with the data http comments body This is a comment receiver_id 4 To make an Ajax request we perform four steps 1. Create an Ajax instance. 2. Choose a response type. 3. Provide a callback. 4. Call . We can create a new Ajax object using var ajax new Ajax . Next we decide what type of data we will request. We can choose to receive the response as FBML JSON or raw content. If we choose FBML Facebook will process the data into a format that can be passed to setInnerFBML. If we choose raw content we could receive either plain text or xHTML to pass to the setTextValue or setInnerXHTML methods respectively. Once we ve picked the type of data we must give Facebook a method to call when the request is complete. We do this by setting the method with a function reference. Usually this method will do something with the data such as update the page. We can optionally provide a method to call when an error occurs by setting the attribute. Finally we call the method to tell Facebook to start the request. There shouldn t be many times when you need to revert to 5. The documentation is at http .

TỪ KHÓA LIÊN QUAN
Đã 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.