鍍金池/ 問答/人工智能  Java  HTML/ jQuery ajax跨域失敗 服務器是java springmvc?

jQuery ajax跨域失敗 服務器是java springmvc?

希望通過設置ajax請求,讓ajax請求可以帶上cookie信息,我按照網上說的添加

    beforeSend: function(xhr) {
            xhr.withCredentials = true;
        }

參考https://www.cnblogs.com/hello...;里面說的方法,也沒辦法成功,下面是我的代碼,希望有過這方面經驗的朋友,能夠好心提供一下幫助。
js

$.ajax({
            url: URL_MANAGER+"/increase-logintime",
            type:"GET",
             dataType:"json",
            timeout : 30000,
            async:false,

            beforeSend: function(xhr) {
                xhr.withCredentials = true;
            },    
            crossDomain: true,            
            success:function(data){
                _data = data;                
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){        
            }
        })

spring mvc xml配置

    <mvc:cors>
        <mvc:mapping path="/**" allowed-origins="http://www.shanhuhaitao.com"
            allowed-methods="POST, GET, OPTIONS, DELETE, PUT"
            allowed-headers="Content-Type, Access-Control-Allow-Headers,Access-Control-Allow-Origin, Authorization, X-Requested-With,Access-Control-Allow-Credentials"
            allow-credentials="true" />
    </mvc:cors>

請求信息

**General**
Request URL: http://localhost:8080/manager/increase-logintime
Request Method: GET
Status Code: 200 OK
Remote Address: [::1]:8080
Referrer Policy: no-referrer-when-downgrade

**response headers**
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://www.shanhuhaitao.com
Content-Type: application/json;charset=UTF-8
Date: Tue, 24 Apr 2018 01:53:28 GMT
Server: Apache-Coyote/1.1
Transfer-Encoding: chunked
Vary: Origin

**request headers**
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Connection: keep-alive
Host: localhost:8080
Origin: http://www.shanhuhaitao.com
Referer: http://www.shanhuhaitao.com/spec-manage.html
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36

實在找不出到底哪里出了問題,希望各位前輩能提供些幫助或者解決的方法線索,萬分感謝

回答
編輯回答
尐飯團

看了下頁面主機是Nginx,方便的話改下配置,用反向代理的方式會比前端折騰跨域省事的多。

2018年9月20日 23:19