This is a created article in which the information may have evolved or changed. When using Golang to do Web applications, the most likely to encounter cross-domain issues, cross-domain is www.a.com access to www.b.com files. But in the browser, for the sake of security, this is not allowed, this is the same origin of JS strategy. Google if you don't understand. 1.golang is a web-ready application that does not use a Web server like Apache because it can construct a Web server on its own. This problem comes, because you use JS to do the foreground, Golang do backstage, so JS pass the value of time, is can be transmitted to the server, and is able to cross-domain access, because the Golang construction of the server and your foreground caused a cross-domain problem. And the value of Ajax is uploaded to the server side, and can be cross-domain access, so I was in the development of the decisive use of it.
2 and after Golang accepts the value, want to return the information to the foreground, this is Golang inside must set can carry on the cross-domain visit. setting is the header that sets it
W.header (). Set (' Access-control-allow-origin ', ' * ')//Allow access to all domains
W.header (). ADD (' access-control-allow-headers ', ' content-type ') type of//header
W.header (). Set (' Content-type ', ' Application/json ')//Return data format is JSON
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.