我正在编写自定义Web服务器。当我在浏览器中输入服务器的URL时,我会在浏览器中正确地写出示例文本。这是我写的HTTP响应:
HTTP/1.1 200 OK\r\n
Server: My Server\r\n
Date: Blah\r\n
Content-Type: text/plain\r\n
\r\n
This is some sample text. This appears in my browser correctly when I connect directly to the server entering the URL.
但是,如果我使用Ajax(jQuery)访问相同的URL,然后在HTML页面上设置元素的innerHTML,我就不会打印任何数据。是否需要在我的Web服务器上设置任何其他标头,以便浏览器的XMLHttpRequest对象检测到响应?
答案 0 :(得分:1)
可能需要Content-Type