简体   繁体   中英

no error in vs2008 but in Chrome Error= XMLHttpRequest cannot load file: Cross origin requests are only supported for HTTP

I'm getting the common Chrome error XMLHttpRequest cannot load file: Cross origin requests are only supported for HTTP.

The thing is however, that I'm authoring my html/jScript stuff in vs2008 . From the IDE I can right click and choose the option "View in Browser". From there, it opens the code up in my default browser (Chrome) and the function i'm using to open my files works perfectly. It works in Chrome. If I go to the project folder and attempt to directly open the html file in Chrome, my jScript that tries to open the file fails and gives the error noted.

I realize that this is a problem that comes up a lot but after googling and looking on stack I can't say that I've seen this particular flavor of it before. Also, I haven't included any code because the code appears to be functional and not the source of the error (like I said it works just fine in Chrome when deployed through vs2008).

I can say for sure that I've done nothing special to the visual studio project. It prompts you with the option to enable web debugging (which I said yes to), but that's about it. The project folder contains an index.html file, about 5 .js files, and a Web.config file generated by the IDE. The Web.config file is kind of big, but I can include it if you think it'd help.

Does anyone have any ideas about what vs2008 could be doing to make my html/jScript project work that Chrome isn't doing on it's own? Thank you for your help.

XMLHttpRequest in Chrome doesn't support access to local files ( file:// ). One work around would be to run an HTTP server locally.

When you're debugging in VS it starts up IIS, which is why it runs without error in that case.

The "file" protocol considers just about anything a cross-origin request (quite possibly because it has no port, nor domain host).

If you attempt to create an XHR to non http(s), then it will obviously fail. That's what you're seeing here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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