得到"错误:jQuery111306513629604596645_1434294948077未被调用"跨域ajax调用时出错?

时间:2015-06-14 15:28:12

标签: jquery ajax

我的AJAX电话是:

$.ajax({
    method: "GET",
    contentType: "application/json; charset=utf-8",
    url: "http://localhost:8080/viewalldoctorprofile",
    dataType: 'jsonp',
    crossDomain: true,
    success : function(json){
        alert("24254");
    },
    error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(thrownError);
    }
});

我可以在浏览器的inspect元素中看到结果JSON,但是我收到错误:

  

错误:未调用jQuery111306513629604596645_1434294948077

请帮帮我。提前谢谢

2 个答案:

答案 0 :(得分:0)

我认为'jQuery111306513629604596645_1434294948077'可能是你JSONP响应的包装器 - 它是否应该在方法中正确包装?

我可以看到你的ajax方法不包含'jsonpCallback'方法。您有类似的问题:Callback function for JSONP with JQuery ajax

答案 1 :(得分:0)

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
    chain.doFilter(req, res);
}

public void init(FilterConfig filterConfig) {}

public void destroy() {}