Local file access JSON data format, no response in Chrome

Source: Internet
Author: User

Cause: A cross-domain issue exists

In JavaScript security, there is a very important security restriction called "homologous policy". A script can read only the properties of a window or document that is identical to its origin (as downloaded by the same host, downloaded by the same port, or downloaded as a protocol).

This restriction is necessary, and if there is no such restriction, an unreliable script in the window can use the DOM method to read the contents of the browser window, and the window may contain private information.

The result is that Chrome prohibits requesting data from a third party when it reads a local relative path script. Chrome's security mechanism restricts XHR requests for local files.

Other browsers:

Firefox: No security prompts and confirmations, cross-domain success.

IE11: The default is to prompt to load unsafe ActiveX controls, asking for confirmation, and cross-domain is OK after confirmation.

About the problem of Ajax cross-domain, interested can also look at this document: How to run things locally

There are a variety of workarounds that can be seen in how to run things locally:

Where on the Nodejs server:

1, open the cmd window, move to the relevant directory, here to E disk for example:

2, Installation Http-server

Use the command to install NPM install HTTP-server -g

-G: For global installation, install to C:\Users\ user name \appdata\roaming\npm\node_modules

If it is only used under the directory, you can move to the relevant directory using npm install HTTP-Server Installation

3. After successful installation, enter Http-server

The default interface is 8080, if you want to set the port yourself, you can use Http-server-p 8000

4. Enter 127.0.0.1:8000 or 192.168.14.117:8000 in the browser

All the files and folders in this directory are displayed on the page.

Reference: http://www.cnblogs.com/AminHuang/p/4371574.html

Local file access JSON data format, no response in Chrome

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.