首页 > 解决方案 > Jquery Ajax Call Rest API 响应为 200 但它抛出错误

问题描述

设置:Spring Boot Rest API - 响应List<Object>

前端:带有 jQ​​uery 的 Html:Ajax 调用

@GetMapping(value = "/getcall")
    @ResponseBody
    public List<Ratio> getCall(@RequestParam("date") String date, HttpServletRequest request,
            HttpServletResponse response) {
        
        return nseCache.getRatio(date);
    }

HTML 调用:

function getall(){
debugger;
 $.ajax({ 
cache: false,

contentType: "application/javascript",
   url: "http://localhost:8080/jsonparser/getcall?date=14-Jan-2021",
  type: 'GET',
    headers: {'Access-Control-Allow-Origin':'*'}, 
   dataType: 'jsonp',
   contentType: "application/json",
    success: function(data){
        console.log("Success"+data);
        
    },
     error: function(data){
     debugger;
        console.log("error "+data);
    },
     failure: function(data){
        console.log("Failure"+data);
    }
});
}

在 Spring Web 应用程序端调试:响应正在传递。

我尝试在 PHP 应用程序上使用相同的 API,并成功获取。但由于限制,我不能使用 jQuery 以外的其他东西。

控制台输出:

调试输出

标签: jqueryspring-bootrest

解决方案


推荐阅读