AJAX返回404找不到

时间:2017-06-08 08:38:02

标签: jquery ajax spring-mvc

我是MVC的新手,并且一直在尝试从对象列表生成一个表,但是ajax调用仍然失败。难道我做错了什么 ? 以下是我的控制器代码

     @RequestMapping(value="/PopulateTable",method = RequestMethod.GET,headers="Accept=*/*")
     public @ResponseBody ArrayList<ReportMetrics> doGet(HttpServletRequest 
      request, HttpServletResponse response) throws ServletException, 
      IOException {
      ArrayList<ReportMetrics> metrics=new ArrayList<ReportMetrics>();
     metrics=responseservice.getReportMetrics();;
     return metrics;
     }

我的Jquery代码是

        <script src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script type="text/javascript">
        $(document).ready(function(){ 
        $("#showTable").click(function(){
               $("div").css("border", "3px solid blue"); 
        $("div").css("border", "3px solid gray");
        $.ajax({
        type: "GET",
        url: "/PopulateTable",
        success: function(data,status)
       {
        createTableByForLoop(data);
        createTableByJqueryEach(data);

       },
       async:   true,
       dataType: 'json'
      }); 
      }); 
      });

已经具有以下依赖性

        <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.13</version>
        </dependency>

error screenshot

我在web.xml上的URI映射

         <servlet-mapping>
         <servlet-name>SplunkPOC</servlet-name>
         <url-pattern>*.htm</url-pattern>
         <url-pattern>*.*</url-pattern>
         </servlet-mapping>

1 个答案:

答案 0 :(得分:1)

尝试更改url,如:

url: "PopulateTable"

参考this link