-2

I have a restful project in spring mvc that use in it jquery code.when my project is restful,all code in jquery not working but when it is not restful all jquery code run correctly.

this is my jquery code.

  function doAjaxPost() {  

  // get the form values  

  $.ajax({  
    type: "POST",  
    url:"/login.htm",//note in restful url change to    

               *** http://localhost:8080/myproject/login ***

    data: "username=" + username + "&password=" + password,  
    success: function(response){
      // we have the response 
      if(response.status == "SUCCESS"){

          //++++++++++

      }else{
          //++++++++++

          }

      }       
    },  
  });  
}  

and my controller code is this:

  @RequestMapping(value="/login.htm",method=RequestMethod.POST)
   public @ResponseBody JsonResponse login(@ModelAttribute(value="user") User user) {
      //==============================
    }

this code run correctly but when it change to restful not working. what is my code problem?

Hadi J
  • 16,989
  • 4
  • 36
  • 62

1 Answers1

1

The problem is that the request gets truncated, it removes the '.htm', because you are trying to access static content, check this if you are trying to get an html and not a service.

How to handle static content in Spring MVC?

In addition, there is a solution if you truly want to get that working, using regex in the RequestMapping annotation.

Read this: Spring MVC @PathVariable with dot (.) is getting truncated

Community
  • 1
  • 1
Luke SpringWalker
  • 1,600
  • 3
  • 19
  • 33