以下JavaScript代碼與出現的Facebook登錄窗口一起使用,並允許用戶登錄。響應值被捕獲,我知道它工作,因爲警報出現在設置的位置,但我無法將值傳遞迴控制器方法。傳遞JavaScript響應變量到彈簧控制器功能
@RequestMapping(value ="/getAccessToken" , method = RequestMethod.POST)
public @ResponseBody String getAccessToken(@RequestBody String token){
System.out.println(token);
return token;
}
Javascript方法叫:
function doLogin() {
FB.login(function(response) {
alert(response);
console.log(response);
if (response.authResponse) {
alert(response.authResponse.userID);
alert(response.authResponse.accessToken);
var Token = response.authResponse.accessToken;
alert(Token);
$.ajax({
type: "POST",
url: "/HelloController/getAccessToken",
data: Token,
success: function (result) {
alert("Token");
},
error: function (result) {
alert("oops");
}
});
document.getElementById('loginBtn').style.
display = 'none';
getUserData();
}}, {perms:'manage_pages',
scope: 'email,public_profile', return_scopes: true});
};
我得到的錯誤是:
WARN 25660 --- [nio-8080-exec-9]
o.s.web.servlet.PageNotFound :
Request method 'POST' not supported
欣賞迴應。
是你用@RequestMapping(「/ HelloController中標註的控制器「)? – reos
@RequestMapping(value =「/ HelloController」,method = RequestMethod.POST)public String getAccessToken( – vbNewbie
)您可以發佈您的整個控制器類嗎? – Mohit