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