Ajax返回200,卻進入了error


在跨域請求中

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");

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM