【发布时间】:2019-07-26 05:35:19
【问题描述】:
基本上,我正在尝试使用 jQuery ajax 从视图中调用控制器,但它没有调用控制器。 我要做的就是将我的令牌值从注册页面传递给控制器,以便我将其值用于用户注册。
< script type = "text/javascript" >
document.getElementById('LoginWithAmazon').onclick = function() {
options = {
scope: 'profile'
};
amazon.Login.authorize(options,
function(response) {
if (response.error) {
alert('oauth error ' + response.error);
return;
}
GetProfileInfo(response.access_token);
});
function GetProfileInfo(token) {
$.ajax({
type: 'GET',
url: '/Account/ProfileInfo',
data: {
token: 'abc'
},
cache: false,
success: function(result) {
alert(result);
}
});
}
function receiveResponse(response) {
if (response != null) {
for (var i = 0; i < response.length; i++) {
alert(response[i].Data);
}
}
}
return false;
};
< /script>/
下面是我的控制器代码
public JsonResult ProfileInfo(string token) {
return Json("test", JsonRequestBehavior.AllowGet);
}
我需要将令牌值从注册页面传递给我的控制器
【问题讨论】:
-
检查控制台是否有错误
-
而且必须是data:JSON.stringify({ token: 'abc'}),
-
请检查控制台是否有错误。对于 URL ,使用
url: 'Url.Action("ProfileInfo", "Account")' -
没有控制台错误。我已经按照您的说法对数据和 url 进行了尊重的更改,现在它在控制台中为 url 提供错误(未找到 404):“localhost:22017/Account/…?{%22token%22 :%22abc%22}&_=1564121140550"
-
添加 url:'@Url.Action("actionName", "controllerName")' 然后试试
标签: c# jquery ajax asp.net-mvc model-view-controller