TAILIEUCHUNG - Phát triển Javascript - part 32

Tham khảo tài liệu 'phát triển javascript - part 32', 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ả | Making POST Requests 283 Obviously this method could be extended to properly encode arrays and other kinds of data as well. Because the encodeURIComponent function isn t guaranteed to be available feature detection is used to conditionally define the method. Encoding Data in For post requests data should be encoded and passed as an argument to the send method. Let s start by writing a test that ensures data is encoded as in Listing . Listing Asserting data sent to post function setUp . function tearDown . TestCase RequestTest . test should encode data function stubFn var object fieldl 13 field2 Lots of data url data object method POST assertSame object 0 Making this test pass isn t so hard as Listing shows. Listing Encoding data if any is available function request url options . options options . Download from 284 Abstracting Browser Differences Ajax We don t need to check if data exists because urlParams was designed to handle a missing argument. Note that because the encoding interface was separated from the ajax interface it would probably be a good idea to add a feature test for it. We could force such a feature test by writing a test that removed the method locally for the duration of the test and assert that the method did not throw an exception. I ll leave that as an exercise. Sending Encoded Data Next up is sending the data. For POST requests we want the data sent to send as Listing specifies. Listing Expecting data to be sent for POST requests test should send data with send for POST function var object fieldl 13 field2 Lots of data var expected object url data object method POST assertEquals expected 0 This test fails .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.