Perfect solution to NODE. JS cross-origin problems

Source: Internet
Author: User
This article mainly introduces NODE. the perfect solution for JS cross-origin problems is of great reference value. If you need a good solution, you can refer to the company's colleagues (front-end) who wrote the page over the past few days and always said they could not get the desired JSON, android iOS can get it, but he is also a newbie and doesn't know why he only knows JavaScript cross-origin problems, and then asks me why I don't know the front-end. I started Baidu,

Some people say that Google Chrome needs to be configured for cross-origin, and then I add -- disable-web-security next to Google Chrome's target.

However, it was found that an error was still reported and the desired data still could not be obtained. There will be no eyebrows when you keep searching.

Today, Baidu inspired me by the PHP cross-domain, So Baidu found node. js cross-origin problem, and finally I am in the app. the js routing settings contain a piece of cross-origin code to perfectly solve the problem:

Var express = require ('express '); var app = express (); // sets the cross-origin access app. all ('*', function (req, res, next) {res. header ("Access-Control-Allow-Origin", "*"); res. header ("Access-Control-Allow-Headers", "X-Requested-With"); res. header ("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS"); res. header ("X-Powered-By", '3.2.1 '); res. header ("Content-Type", "application/json; charset = UTF-8"); next () ;}); // app. listen (0, 8088 );

The above is a small part of the NODE. the perfect solution for JS cross-origin problems is to help you. If you have any questions, please leave a message and the editor will reply to you in time. I would like to thank you for your support for PHP chinnet!

For more articles about the perfect solution to NODE. JS cross-origin problems, please follow the PHP Chinese network!

Related Article

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.