我有一个javascript获取我的facebook'uid'和'accessstoken',有没有办法我可以在触发时将这些值传递给我的Ajax ActionLink,以便我可以重定向到我的'Publish'控制器,它接受2参数。感谢。
<script type="text/javascript">
var uid = 0;
var accesstoken = '';
function grantPermission() {
window.FB.login(function (response) {
if (response.authResponse) {
uid = response.authResponse.userID;
accesstoken = response.authResponse.accessToken;
var postData = { facebookUID: uid, facebookAccessTok: accesstoken };
$.ajax({
url: '@Url.Action("Index","Tab")',
type: 'POST',
data: postData,
dataType: 'json',
success: function (response) {
// process the results from the controller action
// window.location.href = response.Url;
}
});
} else {
console.log('User cancelled login or did not fully authorize.');
alert('User cancelled login');
}
}, { scope: 'publish_stream' });
};
</script>
<html>
<head>
<title>Facebook Login Authentication Example</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"> </script>
</head>
<body>
<h1>Facebook Login Authentication</h1>
<br/>
@Ajax.ActionLink("Proceed", "Publish", "Tab",
new { id = "auth-loginlink" },
new AjaxOptions{UpdateTargetId = "DynamicContainer",
InsertionMode=InsertionMode.Replace,
HttpMethod="POST",
OnSuccess = "grantPermission()"
})
<br/><br/>
<div id="DynamicContainer" style="border: 1px solid #C0C0C0; padding: 1px; width: 500px; height: 400px"></div>
</body>
</html>
发布控制器:
public PartialViewResult Publish( string accTok, string fullImgPath)
{
if (accTok != null && fullImgPath != null)
{
UploadPhoto(accTok, fullImgPath);
// PostToWall(accTok, fullPath);
return PartialView("BlurredPhoto");
}
return PartialView("Blank");
}
答案 0 :(得分:0)
这应该有效,如果TabController上的IndexAction接受两个参数,它们实际上名为facebookUID和facebookAccessTok。