status-async.htm (2940B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>XMLHttpRequest: status/statusText - various responses</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <link rel="help" href="https://xhr.spec.whatwg.org/#the-status-attribute" data-tested-assertations="following::ol/li[1] following::ol/li[3]" /> 8 <link rel="help" href="https://xhr.spec.whatwg.org/#the-statustext-attribute" data-tested-assertations="following::ol/li[1] following::ol/li[3]" /> 9 <link rel="help" href="https://xhr.spec.whatwg.org/#the-getresponseheader()-method" data-tested-assertations="following::ol/li[5]" /> 10 <link rel="help" href="https://xhr.spec.whatwg.org/#the-responsetext-attribute" data-tested-assertations="following::ol/li[4]" /> 11 </head> 12 <body> 13 <div id="log"></div> 14 <script> 15 var counter=0 16 function statusRequest(method, code, text, content, type) { 17 counter++ 18 var test = async_test(document.title +' '+ counter+" (" + method + " " + code + ")") 19 test.step(function() { 20 var client = new XMLHttpRequest() 21 client.onreadystatechange = function(e) { 22 test.step(function() { 23 if(client.readyState > 1) { 24 assert_equals(client.status, code) 25 assert_equals(client.statusText, text) 26 assert_equals(client.getResponseHeader("X-Request-Method"), method) 27 if(client.readyState == 4) { 28 if(method != "HEAD") { 29 if(type == "text/xml") { 30 assert_equals(client.responseXML.documentElement.localName, "x") 31 } 32 assert_equals(client.responseText, content) 33 } 34 test.done() 35 } 36 }else{ 37 assert_equals(client.status, 0) 38 assert_equals(client.statusText, "") 39 } 40 }, this) 41 } 42 client.open(method, "resources/status.py?code=" + encodeURIComponent(code) + "&text=" + text + "&content=" + encodeURIComponent(content) + "&type=" + encodeURIComponent(type)) 43 client.send(null) 44 }) 45 } 46 function status(code, text, content, type) { 47 statusRequest("GET", code, text, content, type) 48 statusRequest("HEAD", code, text, content, type) 49 statusRequest("CHICKEN", code, text, content, type) 50 } 51 status(204, "UNICORNSWIN", "", "") 52 status(401, "OH HELLO", "Not today.", "") 53 status(402, "FIVE BUCKS", "<x>402<\/x>", "text/xml") 54 status(402, "FREE", "Nice!", "text/doesnotmatter") 55 status(402, "402 TEH AWESOME", "", "") 56 status(502, "YO", "", "") 57 status(502, "lowercase", "SWEET POTATO", "text/plain") 58 status(503, "HOUSTON WE HAVE A", "503", "text/plain") 59 status(699, "WAY OUTTA RANGE", "699", "text/plain") 60 </script> 61 </body> 62 </html>