Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SpringMVC使用ajax发送和接收参数_Javascript_Jquery_Ajax_Spring_Spring Mvc - Fatal编程技术网

Javascript SpringMVC使用ajax发送和接收参数

Javascript SpringMVC使用ajax发送和接收参数,javascript,jquery,ajax,spring,spring-mvc,Javascript,Jquery,Ajax,Spring,Spring Mvc,我将请求ajax发送到spring控制器。但当我发送请求时,它没有显示任何内容 我的ajax请求 $(".secs li a").on("click",function(e){ e.preventDefault(); var id = $(this).data("value"); $.ajax({ url:"../tmax", type:"POST", data:{

我将请求ajax发送到spring控制器。但当我发送请求时,它没有显示任何内容

我的ajax请求

  $(".secs li a").on("click",function(e){
      e.preventDefault();
      var id = $(this).data("value");
          $.ajax({
              url:"../tmax",
              type:"POST",
              data:{id:id},
              success: function(response){
                  $("#testdata").html(response);
              }
          })

      })
还有我的控制器

@RequestMapping(value = "/tmax", method = RequestMethod.POST)
public ModelAndView tmax(@RequestParam("id") String id) {
    ModelAndView model = new ModelAndView("tmax");
    model.addObject("dataCOLL", userService.finddataCOLLById(id));
    return model;
}   
我正在home.jsp中发送请求。数据应该得到
tmax.jsp
并显示在home.jsp

我的tmax.jsp页面

<p>Hello World</p>
你好,世界


Thanx

您可以使用$.ajax或$.post来完成

使用$.ajax:

    $.ajax({
      type: 'post',
      url: 'tmax',   //*why you are using double dot?  url:"../tmax",* 
      data: { 
        'field1': 'hello', 
        'field2': 'hello1'
      },
      success: function (response) {
        alert(response.status);
      },
      error: function () {
        alert("error");
      }
   });
    $.post('tmax',
      { 
        'field1': 'hello', 
        'field2': 'hello1'
      },
      function (response, status) {
        alert(response.status);
      }
    );
使用$。post:

    $.ajax({
      type: 'post',
      url: 'tmax',   //*why you are using double dot?  url:"../tmax",* 
      data: { 
        'field1': 'hello', 
        'field2': 'hello1'
      },
      success: function (response) {
        alert(response.status);
      },
      error: function () {
        alert("error");
      }
   });
    $.post('tmax',
      { 
        'field1': 'hello', 
        'field2': 'hello1'
      },
      function (response, status) {
        alert(response.status);
      }
    );
打字过程中的错误成功,现在它开始工作了

  $(".secs li a").on("click",function(e){
      e.preventDefault();
      var id = $(this).data("value");
          $.ajax({
              url:"../tmax",
              type:"POST",
              data:{id:id},
              sucess: function(response){
                  $("#testdata").html(response);
              }
          })

      })

您没有发送参数。您正在发送一个请求体。@M.Deinum现在我传递了参数,得到了404Error@M.Deinum我被你的评论弄糊涂了,他在
ajax
中设置了
data
,你为什么说他不发送参数?@M.Deinum你的意思是
products=MediaType.APPLICATION\u JSON\u VALUE
?嗯,我认为用户可以删除这个配置,因为他没有设置数据类型ajax@M.Deinum为了成功,我在打字过程中犯了一个错误,我写了suces。你的答案不起作用,问题是,我没有得到任何回应。当我只给出URL tmax时,你是如何给出的,我得到了一个错误。如果我给出../tmax,我没有得到任何东西问题是,我没有收到任何错误消息。@AshokCharu请检查您的ajax调用是否正常**$(“.secs li a”)。在(“单击”)上,函数(e){**确认此行是否正常工作,或者尝试提醒您的id