我正在尝试从必须从我的方法重定向的 URL 中检索 token 。它适用于另一种方法,但不适用于此方法。 任何帮助将不胜感激!
Controller 方法:
[HttpPost]
public ActionResult Authorize(int clientId)
{
Session["client_Id"] = clientId;
var client = GoogleAnalyticsHelper.CreateGoogleAnalyticsClient();
string url = client.AuthorizeUrl();
return Redirect(url);
}
JavaScript:
function UpdateClient() {
var baseurl = "/GoogleAnalytics/";
var list = document.getElementById("clientId");
var clientId = list.options[list.selectedIndex].value;
$.ajax({
type: "POST",
async: false,
url: baseurl + "Authorize",
data: { "clientId": clientId },
success: function () {
console.log("success!");
},
error: function (er) {
console.log("an error occured: " + er);
}
});
};
按钮:
<button type="submit" onclick="UpdateClient()" name="button1" class="btn btn-info">Update client/ViewId</button>
最佳答案
我找到了解决方案,问题出在 Google Chrome 上。我成功的解决方案:
success: function (url) {
setTimeout(function () {
window.location.assign(url);
}, 0);
},
关于javascript - MVC C# Redirect() 到字符串 url 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53066738/