jquery $.ajax cross-domain GET works but not POST

守給你的承諾、 提交于 2019-12-24 20:27:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!