以下是這是在我的Spring MVC應用程序中使用AJAX調用JavaScript函數: -如何從Spring Controller訪問Javascript設置的URL屬性?
function someAjax(){
if(window.XMLHttpRequest){
http = new XMLHttpRequest();
}
var username = document.getElementById("username").value;
http.open("GET", "AjaxSameUser?username="+username, true);
http.onreadystatechange=handleResponse;
http.send(null);
}
「AjaxSameUser」 被RequestMapped到控制器,它重定向到AjaxSameUser.jsp。
我也可以從AjaxSameUser.jsp獲取靜態內容並使用http.responseText使用它。
現在,我想訪問此控制器中的用戶名。我該怎麼做呢??
其實這是註冊頁面的用戶名。我想檢查用戶輸入的用戶名是否已經存在於當前數據庫中。
我已經嘗試使用@ModelAttribute考慮到該用戶名將在請求範圍內設置。但是我無法從Javascript訪問這個值集。