I am wanting to send an AJAX POST request from domain.com to sub.domain.com. I know that I need to enable CORS, however after reading online I am unsure if this needs to be done on the sending server or the receiving server, or both?
Could I just add the below to my receiving servers nginx?
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' 'domain.com';
add_header 'Access-Control-Allow-Methods' 'POST';
}
Does something need to be set on the sending servers configuration, or is just doing this in the code sufficient?
$.ajax({
type: "POST",
url: sub.domain.com,
data: data,
success: success,
dataType: dataType
});