TAILIEUCHUNG - Tương tác giữa PHP và jQuery - part 9

Sử dụng phương pháp AJAX Viết tắt Có một số đơn giản, sử dụng một chức năng, có sẵn để thực hiện nhiệm vụ phổ biến AJAX. Tóm lại, những phương pháp này chỉ đơn giản là viết tắt các chức năng bao bọc mà gọi $. Ajax () với một số các thông số đã được thiết lập. Sử dụng các phương pháp này sẽ phải chịu một hình phạt thực hiện nhẹ, kể từ khi bạn đang chủ yếu kêu gọi một phương thức để thiết lập các thông số và các cuộc gọ. | CHAPTER 2 COMMON JQUERY ACTIONS AND METHODS This results in the paragraph s contents being replaced with new content from see Figure 2-23 . Figure 2-23. The result ofan AJAX call after setting default options These defaults can be overwritten in subsequent calls to .ajax by simply redefining the option in the new call .ajax type GET data newvar1 value3 newvar2 value4 This results in the data being sent using GET see Figure 2-24 . 81 CHAPTER 2 COMMON JQUERY ACTIONS AND METHODS Figure 2-24. The result after overriding the default type option with CET Using Shorthand AJAX Methods There are several simple one-use functions available for performing common AJAX tasks. In a nutshell these shorthand methods are simply wrapper functions that call .ajax with some of the parameters already set. Using these methods will incur a slight performance penalty since you re essentially calling a method that sets up parameters and calls .ajax within itself. However the convenience of using shorthand methods really speeds up development in many scripts. .get and .post For standard GET and POST requests the .get and .post functions are easy to use. Both take four arguments the URL to which the request is to be sent optional data to be sent to the remote script an optional callback to be executed if the request is successful and an optional dataType setting. To load the result of using GET with no data sent use the following .get function data bar .css background yellow .html data 82 CHAPTER 2 COMMON JQUERY ACTIONS AND METHODS To send a request with data using POST the following code could be used .post var1 value function data bar .css background yellow .html data .getJSON When loading JSON data .getJSON is a shortcut function. It accepts the URL to which requests are sent optional data and an optional callback function. To run an example of this function another test file needs to be created create a new file called in the testing folder and

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.