jquery $ .ajax跨域GET工作但不是POST

时间:2013-05-06 16:05:58

标签: jquery ajax cross-domain jersey

我无法弄清楚为什么GET跨域请求正在运行,但使用完全相同的服务器URL的POST请求却没有。我在服务器上设置了以下响应头(使用JERSEY)来设置所有请求方法(GET,POST,PUT,DELETE和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请求正在跨域工作

$.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);
                }
            });

但POST请求不是

$.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);
            }
        });

0 个答案:

没有答案