No Access-Control-Allow-Origin header is present on the requested resource

前端 未结 4 1298
感情败类
感情败类 2020-12-05 05:08

I want to access information from same domain but with different port number, To allow this I am adding Access-Control-Allow-Origin with the response header.

4条回答
  •  青春惊慌失措
    2020-12-05 05:59

    You are missing 'json' dataType in the $.post() method:

    $.post('http://www.example.com:PORT_NUMBER/MYSERVLET',{MyParam: 'value'})
            .done(function(data){
                      alert(data);
             }, "json");
             //-^^^^^^-------here
    

    Updates:

    try with this:

    response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
    

提交回复
热议问题