This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 4th, 2013  |  syntax: None  |  size: 1.73 KB  |  views: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <li>
  2.             <form id="byConsumes" class="readJsonForm" action="<c:url value="/mapping/consumes" />" method="post">
  3.                 <input id="byConsumesSubmit" type="submit" value="By consumes" />
  4.             </form>
  5.         </li>
  6.        
  7. $("form.readJsonForm").submit(function() {          
  8.  
  9.     var form = $(this);                 // Variabile che si riferisce all'elemento nel DOM che ha scatenato l'evento click (il form)
  10.     var button = form.children(":first");       // Seleziona il bottone submit
  11.  
  12.     var data = form.hasClass("invalid") ?       // OPERATORE CONDIZIONALE: il form ha classe "invalid" ?
  13.             "{ "foo": "bar" }" :            // SI: foo = bar
  14.             "{ "foo": "bar", "fruit": "apple" }";   // NO: foo= bar ; fruit = apple
  15.  
  16.  
  17.     /* AJAX CALL PARAMETER:
  18.        type: Say to the servet tath the request is a POST HTTP Request
  19.        url: The address to which to send the call  
  20.        data: the content of my data variable
  21.        contentType: an object having JSON format
  22.        dataType: the type of content returned by the server
  23.     */
  24.     $.ajax({ type: "POST", url: form.attr("action"), data: data, contentType: "application/json", dataType: "text",
  25.         success: function(text) { MvcUtil.showSuccessResponse(text, button); },
  26.         error: function(xhr) { MvcUtil.showErrorResponse(xhr.responseText, button); }});
  27.  
  28.     return false;
  29. });
  30.        
  31. @RequestMapping(value="/mapping/consumes", method=RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE)
  32. public @ResponseBody String byConsumes(@RequestBody JavaBean javaBean) {
  33.     return "Mapped by path + method + consumable media type (javaBean '" + javaBean + "')";
  34. }
  35.        
  36. JavaBean parameter = new JavaBean();
  37. parameter.setFoo("bar");
  38. parameter.setFruit("apple");
clone this paste RAW Paste Data