send data with Ajax to Spring Controller -
i have page jsp want send data using ajax controller . doesn t work .i got error in console : error 404 .
my controller :
@requestmapping(value="/sendemail",method=requestmethod.post) public void sendemail(){ } @requestmapping(value="/sendemail",method=requestmethod.get) public void sendemailget(){ }
in page jsp :
<div class="row col-xs-10 col-md-6 form-group"> <!-- <textarea rows="5" class="form-control"></textarea> --> <springform:textarea path="message" name="message" class="form-control" rows="5"/> </div> <div class="row"> <span class="col-xs-12 col-md-4"> <a class="btn btn-info navbar-btn navbar-right" id="sendemail">envoyer email</a> </span> </div> <script> $('#sendemail').click( function(){ $.ajax({ url:'/sendemail', type:"post", datatype:'json', contenttype : "application/json; charset=utf-8", success : function() { console.log("success: "); }, error : function() { console.log("error: "); }, done : function() { console.log("done"); } }); }); </script>
i got error in browser console :
request url:http://localhost:8989/sendemail request method:post status code:404 remote address:[::1]:8989 referrer policy:no-referrer-when-downgrade response headers view source content-language:fr-fr content-type:application/json;charset=utf-8 date:thu, 14 sep 2017 04:33:30 gmt transfer-encoding:chunked request headers view source accept:application/json, text/javascript, */*; q=0.01 accept-encoding:gzip, deflate, br accept-language:fr-fr,fr;q=0.8,en-us;q=0.6,en;q=0.4 connection:keep-alive content-length:0 content-type:application/json; charset=utf-8 cookie:jsessionid=b40e408bbc4209d1cecc9336b3ad3ec1 host:localhost:8989 origin:http://localhost:8989 referer:http://localhost:8989/detail/1 user-agent:mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, gecko) chrome/60.0.3112.113 safari/537.36 x-requested-with:xmlhttprequest
like see didn t send thing controller , wanted start empty see if request reach controller , didn t, thank you.
Comments
Post a Comment