JavaScript cross-domain access to cors issues

Source: Internet
Author: User

An error was encountered while attempting to access the rest server from a Web front-end using an HTTP request request: XMLHttpRequest cannot load http://localhost:8080/ping. No ' Access-control-allow-origin ' header is present on the requested resource. Origin ' http://localhost:63342 ' is therefore not allowed access.

This error is caused by the Ajax cross-domain access to another domain's service, which in general can be handled by using JSONP, which is to pass a callback function to the server side, and then wrap the callback function on the server side to the outside of the JSON object and return it to the client. However, JSONP only takes effect on get requests, does not take effect on post, PUT, delete, and because JSON itself is inherently unsafe (see this link), many clients use post to get the JSON response. So now a lot of the use of cors (see Wiki link for details), is actually very simple, just need to add a header to your server response header, ("Access-control-allow-origin", "Http://domain") Can be solved, the standard is supported by most browsers, including the mobile side.



JavaScript cross-domain access to cors issues

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.