Ajax request from jax-rs web service

后端 未结 1 1466
耶瑟儿~
耶瑟儿~ 2021-01-28 21:10

While sending a post request from my tomcat web service i got an error as below: \" Response to preflight request doesn\'t pass access control check: No \'Access-Control

相关标签:
1条回答
  • 2021-01-28 21:39

    You say "I tried to enable the CORS filter and tried to send get request that working fine."

    Do you mean that GET method works but POST not? If so you must allow it on your REST service/terminal and also these settings header("Access-Control-Allow-Origin", "*") header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT")

    Finally, if by any chance your AJAX still returns failed try

    $.ajax({
        type : "POST",
        url : "http://localhost:8080/userManagement/rest/Traffic/users2",
        contentType :"application/json; charSet=UTF-8",
        data : d,
        dataType : "json",
    **xhrFields: {
        withCredentials: true
    },
    crossDomain: true,**
    beforeSend: function (xhr){ 
            console.log('Before');
            xhr.setRequestHeader('Authorization', make_base_auth(user, pass)); 
        }'
    
    0 讨论(0)
提交回复
热议问题