response-data-arraybuffer.htm (1949B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <link rel="help" href="https://xhr.spec.whatwg.org/#the-responsetype-attribute" data-tested-assertations="following::ol[1]/li[4]" /> 5 <link rel="help" href="https://xhr.spec.whatwg.org/#the-response-attribute" data-tested-assertations="following::a[contains(@href,'#arraybuffer-response-entity-body')]/.." /> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <title>XMLHttpRequest: The response attribute: ArrayBuffer data</title> 9 </head> 10 11 <body> 12 <div id="log"></div> 13 14 <script type="text/javascript"> 15 var test = async_test(); 16 17 test.step(function() 18 { 19 var xhr = new XMLHttpRequest(); 20 21 xhr.onreadystatechange = function() 22 { 23 if (xhr.readyState == 4) 24 { 25 test.step(function() 26 { 27 assert_equals(xhr.status, 200); 28 29 var buf = xhr.response; 30 assert_true(buf instanceof ArrayBuffer); 31 32 var arr = new Uint8Array(buf); 33 assert_equals(arr.length, 5); 34 assert_equals(arr[0], 0x48, "Expect 'H'"); 35 assert_equals(arr[1], 0x65, "Expect 'e'"); 36 assert_equals(arr[2], 0x6c, "Expect 'l'"); 37 assert_equals(arr[3], 0x6c, "Expect 'l'"); 38 assert_equals(arr[4], 0x6f, "Expect 'o'"); 39 40 assert_equals(xhr.response, xhr.response, 41 "Response should be cached"); 42 43 test.done(); 44 }); 45 } 46 }; 47 48 xhr.open("GET", "./resources/content.py?content=Hello", true); 49 xhr.responseType = "arraybuffer"; 50 xhr.send(); 51 }); 52 </script> 53 </body> 54 </html>