How to solve the problem of cross-domain requests POST

This article mainly introduces how to solve the problem of cross-domain request Post, the introduction is very detailed, with certain reference value, interested friends must have read!

Cross-domain Request Post Solution

Cookie is generally unable to cross domain, or even POST requests are unable to cross-domain.
// Request code sample $ .ajax ({URL: URL, TYPE: “post”, data: metadata, datatype: ‘json’, xhrfields: {withcredentials: true}, Crossdomain: True, Success: function () {}, error: function () {}};
   1. By default, Ajax (
xmlhttpRequest () object and IE

Microsoft.xmlhttp object ) is subject to homologous strategies that do not allow cross-domain requests. 2, JSONP’s cross-domain is to use the page dynamically add Script tag to reference cross-domain resources to avoid this limit, but no post method
.

: Server-end settings, allowing AJAX request cross-domain

## server setting allows cross-domain code, EG: header “Access-Control-Allow-Credentials: True”); Header (“Access-COntrol-allow-origin: http://www.xxx.com “); ## After success, Response Headers in the interface will see the following allowed information {Access-Control-Allow-Credentials: True Access- CONTROL-Allow-Headers: X-Requested-with, Content-Type Access-Control-Allow-Methods: Post Access-Control-allow-Origin: http://www.Aipai.com}
Cookies’ cross-domain solution
  AJAX cross-domain request problem solved, but when the backend needs to obtain cookies through the interface, there is also a cross-domain problem of cookies  
Cookies cross-domain solution

: Add the following parameters to the request, request head information will accompany the cookies information

// code $ .ajax ({… xhrfields : {withcredentials: true}, …}); How to solve all the contents of the cross-domain request POST, thank you for reading! I hope to share the content to everyone Help, more related knowledge, welcome to pay attention to Tumi Yun Industry News!
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment