我在使用AJAX發佈表單時遇到了麻煩。Spring MVC - AJAX表單發佈的問題
這裏是我的Ajax調用:
function submit() {
$.ajax({
type: "POST",
url: "http://localhost:8080/executeRetrieve",
data: $("#form").serialize(),
dataType: "json",
success: function(data) {
alert(data);
}
})
}
這裏是我的HTML表單(他們是在同一頁):
<form id="form" method="post">
User <input type="text" name="user" id="user"/><br />
Password <input type="password" name="password" id="password"/><br />
<input type="submit" value="Submit" onclick="submit()"/>
而且也,這是我的動作:
@RequestMapping(value = "/executeRetrieve", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
public @ResponseBody String executeRetrieve(HttpServletRequest request) {
JSONObject json = new JSONObject();
json.put("message", "hello");
return json.toString();
}
我是困惑。不應該那樣工作?我一直在尋找至少3天的解決方案,我無法理解發生了什麼。行動方法甚至沒有達到。有人會知道我犯了什麼錯誤嗎?
在此先感謝,好朋友。
有沒有網絡流量? – BevynQ
@BevynQ對不起? –
使用chrome,檢查元素點擊網絡。然後嘗試解僱你的活動。你應該看到一些網絡流量。特別是一個職位。 – BevynQ