Ajax For Dumies phần 5

Tham khảo tài liệu 'ajax for dumies phần 5', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 110 Part II Programming in Ajax__ echo xml version echo options foreach options as value echo option echo value echo option echo options I ve heard of rare PHP installations where _POST wouldn t work with Ajax applications when you use the POST method in which case you have to use HTTP_RAW_POST_DATA instead. This technique gives you the raw data string sent to the PHP script such as a 5 b 6 c Now is the time and it s up to you to extract your data from it. How do you use the POST method in your JavaScript It isn t as easy as just changing GET to POST when you open the connection to the server POST url Won t work by itself It isn t as easy as that because you don t URL-encode your data when you use POST. Instead you have to explicitly send that data by using the XMLHttpRequest object s send method. Here s what you do. You set up the URL to open without any URL encoding this way in the getOptions function which is the function that communicates with the server function getOptions scheme var url Then you configure the XMLHttpRequest object to use this URL. You do this by using the open method and by specifying that you want to use the POST method function getOptions scheme var url if XMLHttpRequestObject POST url Chapter 3 Getting to Know Ajax 111 To use the POST method you should also set an HTTP header for the request that indicates the data in the request will be set up in the standard POST way. Here s what that looks like function getOptions scheme var url if XMLHttpRequestObject POST url Content-Typei application x-www-form-urlencoded Then you can connect an anonymous function to the XMLHttpRequest object s onreadystatechange property as before to handle asynchronous requests as shown here function getOptions scheme var url if XMLHttpRequestObject .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.