简体   繁体   English

XMLHttpRequest请求的结果为ReadyState 4,状态为200

[英]XMLHttpRequest request is resultin in ReadyState 4 and status is 200

I am trying to make a XMLHttpRequest Request to a content which is on local, runnin on local webserver from a HTML File and javascript residing locally. 我正在尝试向本地内容,从本地HTML服务器上运行的HTML文件和JavaScript发出XMLHttpRequest请求。

it will hit the webserver request, and then even thou it sends the data back, in my javascript, at once I get readyState 4 and status as 0. 它将到达网络服务器请求,然后即使您将其发送回数据,也立即在我的JavaScript中,我得到readyState 4,状态为0。

If i try putting the pages in the webserver foloder and access them as webpage slke http;//localhost/ filename then it works fine. 如果我尝试将页面放在网络服务器文件中,并以slke http; /// localhost / filename的形式访问它们,则可以正常工作。

This is to do with the fact that HTTP status codes are returned by web servers and, since you're accessing the local file system, a status code can't be returned -- hence Unknown (0) . 这与以下事实有关:HTTP状态代码由Web服务器返回,并且由于您正在访问本地文件系统,因此无法返回状态代码-因此为Unknown (0) Some links: 一些链接:


Following your comments, it's a little clearer as to what is causing your problem. 根据您的评论,可以更清楚地了解引起问题的原因。 XMLHttpRequests are restricted in each browser by the Same origin policy . XMLHttpRequests在每个浏览器中均受“ 同源”策略限制 If you try to access a file on a different domain, port or protocol the request will return a status code of 0 and nothing for responseText . 如果您尝试访问其他域,端口或协议上的文件,则请求将返回状态代码0,而responseText则返回零。 The most suitable workaround for the time being is JSON with Padding . 目前最合适的解决方法是JSON with Padding

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM