html로 페이지입니다 :XHR에서 responseText는 빈 문자열을
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>xhr</title>
</head>
<body>
<script>
var xhr_test = new XMLHttpRequest();
xhr_test.open("GET","xhrtest",true);
xhr_test.send();
alert(xhr_test.responseText);
</script>
</body>
</html>
main.py 파일 :
import webapp2
from handlers import cookies,pages
application = webapp2.WSGIApplication([
('/xhr',pages.XHR),
('/xhrtest', cookies.XHRTest)
],
debug=True)
요청 핸들러 :
class XHRTest(webapp2.RequestHandler):
def get(self):
self.response.write('0')
하고,
class XHR(webapp2.RequestHandler):
def get(self):
f = open('static/html/xhr.html','r')
self.response.write(f.read())
이제 URL localhost:8080/xhrtest
에 접속하면 브라우저는 즉시 페이지 내용으로 응답 0
을 표시합니다. 간접적으로 /xhrtest
안타 경고 상자에 빈 문자열을 팝업 URL localhost:8080/xhr
친
하지만 네트워크 탭에서 확인 크롬의 응답 탭합니다 (에서 responseText은 빈 문자열), I는 요청의 응답이 0
것을 볼 수 있습니다.
그렇다면 xhr_test.responseText
은 왜 동일한 응답을 표시 할 수 없습니까?
내 문제는 백엔드에서 gzip을 사용하지 않는 것이 문제였습니다. –