java - multiple post ajax to different methods in the same controller -
i newbie jquery, js, java, etc world. using spring mvc maven.
i have jsp file 2 post functions different url matching 2 different methods in same controller.
so expected =>
caseasend
(in mytest.jsp) posts datacaseahandler
(in mycontroller.java)casebend
(in mytest.jsp) posts datacasebhandler
(in mycontroller.java)
but both caseasend
and casebsend
ends same handler in mycontroller.java
[note] caseasend
, casebsend
called different behaviors in jsp file , need process differently in controller. should handled seperately
[q] how can make 1:1 mapping between post ajax
, handling method
in mycontroller.java. why both posts goes same method different url?
[my code this] :
1) mytest.jsp
function caseasend(title, id){ $.ajax({ url:'/test/{casea}.html', data: 'title='+title+'&id='+id+'&something'+something, type:"post", success: function(response){ alert('casea done'); } }); } function casebsend(title, id){ //something wrong $.ajax({ url:'/test/{caseb}.html', data: 'title='+title+'&id='+id+'&somethingelse='+somethingelse, type:"post", success: function(response){ alert('caseb done!'); } }); }
2) mycontroller.java
@requestmapping(value="/test/{casea}", method = requestmethod.post) public @responsebody string caseahandler(@requestbody string response) { … ... } @requestmapping(value="/test/{caseb}", method = requestmethod.post) public @responsebody string casebhandler(@requestbody string response) { { …. … }
i have looked other answers similar few days couldn't cleared out. doing incorrect here?
maybe obvious or simple knows world. can't clear out why both posts goes same method different url. appreciated if clear out.
value in {} url placeholder. caseahandler react on /test/a, /test/bb, etc. urls.
if need separate handlers react on separate url try remove {}.
@requestmapping(value="/test/casea", method = requestmethod.post) @requestmapping(value="/test/caseb", method = requestmethod.post)
and same in jsp
Comments
Post a Comment