我有一个页面JSP,我希望使用AJAX将数据发送到My Controller。但它不起作用。我在控制台出错:错误404。
我的控制器:
@RequestMapping(value="/sendemail",method=RequestMethod.POST)
public void sendemail(){
}
@RequestMapping(value="/sendemail",method=RequestMethod.GET)
public void sendemailget(){
}
在我的页面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>
我在浏览器控制台中收到此错误:
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, like Gecko) Chrome/60.0.3112.113 Safari/537.36
X-Requested-With:XMLHttpRequest
就像你看到我没有向我的控制器发送任何东西,我只想从空开始查看请求是否到达控制器,但它没有,谢谢。