1. 程式人生 > >Ajax返回200,卻進入了error

Ajax返回200,卻進入了error

fun ring del true con window cal .ajax then

在跨域請求中

ajax中,設置了

xhrFields: { withCredentials: true} ,相應的應在後臺也應該設置
ajax:
$.ajax({
                type: ‘post‘,
                xhrFields: {
                    withCredentials: true
                },
                url: "http://localhost:8060/authentication/form",
                data: {
                    
‘username‘: username, ‘password‘: password, ‘imageCode‘:imageCode }, dataType: "text" }).success(function (data) { alert("登陸成功"); /*將返回信息同時存入sessionStorage,cookie*/ sessionStorage.setItem(
‘token‘, JSON.stringify(data)); document.cookie = "info="+JSON.stringify(data); //window.location.href="index.html" }).error(function () { alert("賬號密碼不正確"); });

java

 response.setCharacterEncoding("UTF-8");
        response.setContentType(
"application/json;charset=utf-8"); response.setHeader("Access-Control-Allow-Credentials","true"); response.setHeader("Access-Control-Allow-Origin", "http://admin.wenfan.com"); //允許跨域請求 response.setHeader("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS"); response.setHeader("Access-Control-Allow-Headers","Authorization");

Ajax返回200,卻進入了error