The processing method of Ajax cross-domain

Source: Internet
Author: User

When we are developing projects, we typically use AJAX to request data, but there are cross-domain issues when using AJAX.

Why is there a cross-domain problem?

Cross-domain problems arise from the same-origin JavaScript policy, which means that access is permitted in the same domain name, protocol name, and port number, meaning that JavaScript only allows access to resource files under its own domain.


How to troubleshoot cross-domain

There are three ways to solve cross-domain:

    • Jsonp

In writing Ajax is set DATATYPE:JSONP it means to allow the server-side integration scrip tags back to the client, through JavaScript callback form can be solid cross-domain access.

    • Only need to fill in the response header on the server side

Header ("access-control-allow-origin:*");/* Asterisks indicate that all domains are acceptable, */

Header ("Access-control-allow-methods:get,post");

    • Agent (This method is seen on the Internet, detailed can refer to other blogs)

The processing method of Ajax cross-domain

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.