Cross-domain issues

Source: Internet
Author: User

3 ways to solve the problem of Ajax cross-domain
1, with the response header: Add the response header on the server:
The Page Setup response header allows Ajax cross-domain access: both:
2, using the proxy: In the current server load a proxy server, Proxy Server allows Ajax cross-domain, in a proxy server sent to the primary server;
3. Using Jsonp:
<script src= "Http://localhost:3000/showAll" ></script>src point to the address of the server you want to link to, the data returned by the service as JS code execution; This is a jsonp principle, The equivalent of using a script tag to send an AJAX-like request (only the request address); Request http://localhost:3000 the ShowAll method below;
Script,link img and other tags can be cross-domain;
Methods of jquery Encapsulation
Using the Jsonp method, add the following two parameters to Ajax;
1, datatype and jsonpcallback two parameters in $.ajax, the script method is encapsulated into Ajax form, then as long as the datatype is not Ajax, is Jsonp method;
2, principle: First in use $. Ajax generates a script tag, and then defines a method to receive the returned data to implement cross-domain, but here this Ajax is not Ajax, the implementation of the mechanism is actually SJONP, sensitive data do not cross-domain;
3, JOSNP does not support post method;
4, $.ajax ({type: "Get", url: "Http://localhost:3000/showAll", DataType: "Jsonp", Jsonpcallback: "CD" (defines the method name that the server returns, If the server returned is not a method, can be omitted;),})

Cross-domain 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.