问题
I cannot figure out why a GET cross-domain request is working, but the POST request using the exact same server URL is not. I have set the following response headers set on the server (using JERSEY) for ALL request methods (GET, POST, PUT, DELETE, and OPTIONS):
header("Access-Control-Allow-Origin", "*")
header("Access-Control-Allow-Credentials", "true")
header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
header("Access-Control-Allow-Headers", "accept, origin, authorization, content-type, content-length, connection, x-requested-with, user-agent")
GET requests are working cross-domain
$.ajax({
type:"GET",
url: base_url + "workoutdays?memberId=100350194",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", auth);
},
success: function(msg)
{
$('#results').html(msg[0].workoutName);
},
error: function (xhRequest, errorText, thrownError)
{
alert(errorText);
}
});
but POST requests are not
$.ajax({
type:"POST",
url: base_url + "workoutdays?memberId=100350194",
data: {workoutId : "4"},
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", auth);
},
success: function(msg)
{
$('#results').html(msg[0].workoutName);
},
error: function (xhRequest, errorText, thrownError)
{
alert(errorText);
}
});
来源:https://stackoverflow.com/questions/16402635/jquery-ajax-cross-domain-get-works-but-not-post