我有一个全局ajaxComplete处理程序:
$('body').ajaxComplete(function (event, request, settings) {
if (request.getResponseHeader('REQUIRES_AUTH') === '1') {
alert("unauthorized");
};
});
Run Code Online (Sandbox Code Playgroud)
request总是在未定义中的问题仅被填充event.
你能解释一下为什么吗?
ajax请求的示例:
$.ajax({
cache: false,
data: "GET",
url: url,
success: function (content) {
$('#modal').html(content);
$('#modal').modal();
}
});
Run Code Online (Sandbox Code Playgroud)
更新:
来自API文档(感谢Austin Mullins):
但是,从jQuery 1.8开始,.ajaxComplete()方法只应附加到文档.
我已将代码更改为:
$(document).ajaxComplete(function (event, request, settings) {
if (request.getResponseHeader('REQUIRES_AUTH') === '1') {
alert("unauthorized");
};
});
Run Code Online (Sandbox Code Playgroud)
但现在我收到了错误:
TypeError: document.createDocumentFragment is not a function
safeFrag = document.createDocumentFragment(); (jquery-1.9.0.js (line 5800))
Run Code Online (Sandbox Code Playgroud)
浏览器是Firefox 19.0.2
解决方案: 问题出在Jquery 1.9.0版本中.我已更新到1.9.1,错误消失了.感谢波阿斯.
如何List<byte[]>在一个byte[]数组或一个数组中进行转换Stream?
我有以下路线:
routes.MapRoute("Event Overview", "{city}/{type}/{id}",
new {city="LA", controller = "BaseEvent", action = "EventOverview"}, new {city = new CityConstraint()});
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud)
而且,我网站上的几个链接:
@Html.ActionLink("Make", "EventOverview", "BaseEvent", new { id = eventInfo.Key.OID, type = eventInfo.Key.XPObjectType.TypeName.GetShortTypeName(), activeTab = "#scheduleLink", session = eventInfo.Key.EventSchedules[0].SessionId, hall = eventInfo.Key.EventSchedules[0].HallId, client = eventInfo.Key.EventSchedules[0].BasePlace.PremieraClientId}, null)
@Html.ActionLink("Make", "EventOverview", "BaseEvent", new { id = eventInfo.Key.OID, type = eventInfo.Key.XPObjectType.TypeName.GetShortTypeName(), activeTab …Run Code Online (Sandbox Code Playgroud) 我有jwt auth:
var messageHandlers = new JwtMessageHandler(_serviceProvider);
app.UseJwtBearerAuthentication(new JwtBearerOptions
{
AutomaticAuthenticate = true,
AutomaticChallenge = true,
Events = new JwtBearerEvents
{
OnMessageReceived = messageHandlers.OnMessageReceived,
},
TokenValidationParameters = tokenValidationParameters
});
Run Code Online (Sandbox Code Playgroud)
这JwtMessageHandler是我的自定义处理程序.在处理程序中,我必须对数据库进行一些查询,因此我传递ServiceProvider并解析了我的用户服务:
public class JwtMessageHandler
{
private IUserService _userService;
public async Task OnMessageReceived(MessageReceivedContext arg)
{
//parsing header, get claims from token
...
_userService = (IUserService)arg.HttpContext.RequestServices.GetService(typeof(IUserService));
var isRoleChanged = await _userService.IsRoleChanged(tokenObject.Subject, rolesFromToken);
if (isRoleChanged)
{
GenerateBadResponse(arg);
return;
}
var canLogin = await _userService.CanLogin(tokenObject.Subject);
if (!canLogin)
{
GenerateBadResponse(arg);
return;
} …Run Code Online (Sandbox Code Playgroud) c# asp.net entity-framework entity-framework-core asp.net-core
我有以下脚本:
function OpenIdLogon(e) {
$.post("/Account/OpenIdLogOn/", { token: e }, function (data) {
$("#userNavigation").html(data);
$(".auth_box").hide();
$(".kb_fading").hide();
});
}
Run Code Online (Sandbox Code Playgroud)
这是行动:
public ActionResult OpenIdLogOn(string token)
{
WebClient cli = new WebClient();
string json = cli.DownloadString(new Uri("http://ulogin.ru/token.php?token=" + Request.Params["token"] + "&host=" + Request.Url.Host));
var obj = JObject.Parse(json);
if (obj["error"] == null)
{
var userName = obj["nickname"].Value<string>();
var email = obj["email"].Value<string>();
FormsAuthentication.SetAuthCookie(userName, true);
}
return PartialView("UserNavigation");
}
Run Code Online (Sandbox Code Playgroud)
而且,我的用户导航:
@if (Request.IsAuthenticated)
{
<a href="#" class="username"><span>@Context.User.Identity.Name</span><i class="icon iUser"></i></a>
<ul class="headLine_link">
<li><a href="#">Profile</a></li>
<li>
@Html.ActionLink("Logg Off", "LogOff", "Account", …Run Code Online (Sandbox Code Playgroud) 在datePicker中选中20.04.2012.我想得到这个值,格式化并存储在变量中.我用这个代码:
var date = $("#scheduleDate").datepicker({ dateFormat: 'dd,MM,yyyy' }).val();
Run Code Online (Sandbox Code Playgroud)
但结果是20.04.2012.另外,我尝试了这段代码:
var dateTypeVar = $('#scheduleDate').datepicker('getDate');
$.datepicker.formatDate('dd-MM-yy', dateTypeVar);
Run Code Online (Sandbox Code Playgroud)
结果是Fri Apr 20 2012 00:00:00 GMT+0600.
我想得到以下内容:20, April, 2012
如何正确格式化?
谢谢.
我有一个div包含大约100个其他div元素.每个div元素都有top和left属性.如何找到div具有最大left属性的?
我需要最好的表现.谢谢.
如何通过名称的一部分获取数据属性的值?
例如:
<div data-pcp-email="some text" data-pcp-order="some int" data-ref="some data"></div>
Run Code Online (Sandbox Code Playgroud)
并且假设,我希望以所有数据属性开头data-pcp-:结果必须是data-pcp-email和 data-pcp-order
我无法找到delay或wait履行jQuery承诺.我在SO上找到了一个函数(使用jQuery.Deferred来避免嵌套的setTimeout回调):
function delay(time) {
return function () {
console.log("Delaying");
var ret = new $.Deferred();
setTimeout(function () {
ret.resolve();
}, time);
return ret;
};
}
Run Code Online (Sandbox Code Playgroud)
而且,这是我使用它的方式:
run: function () {
return $()
.promise()
.then(function () {
console.log("call together");
console.log("call together");
})
.then(delay(2000))
.then(function () {
console.log("call first");
})
.then(delay(2000))
.then(function () {
console.log("call second");
})
}
Run Code Online (Sandbox Code Playgroud)
我想扩展我可以编写的promise或deferred对象:
run: function () {
return $()
.promise()
.then(function () {
console.log("call together");
console.log("call together");
})
.delay(2000) …Run Code Online (Sandbox Code Playgroud) 我想包装所有的http响应.
例如,我们有一个返回一些JSON数据的动作:
public IActionResult Get()
{
var res = new
{
MessageBody = "Test",
SomeData = 1
};
return Ok(res);
}
Run Code Online (Sandbox Code Playgroud)
我希望我的回答如下:
{
"StatusCode":200,
"Result":
{
"MessageBody ":"Test",
"SomeData":1
}
}
Run Code Online (Sandbox Code Playgroud)
如果有错误,则响应必须包含响应中的ErrorMessage字段.
在mvc 5中我使用过DelegationHandler,但是在asp.net核心中这个类没有实现.现在,我们必须使用中间件.
这是mvc 5的代码:
public class WrappingHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var response = await base.SendAsync(request, cancellationToken);
return BuildApiResponse(request, response);
}
private static HttpResponseMessage BuildApiResponse(HttpRequestMessage request, HttpResponseMessage response)
{
object content;
string errorMessage = null;
if …Run Code Online (Sandbox Code Playgroud) jquery ×5
c# ×3
asp.net-core ×2
asp.net-mvc ×2
.net ×1
ajax ×1
asp.net ×1
asp.net5 ×1
datepicker ×1
javascript ×1
jquery-1.9 ×1
jquery-ui ×1
promise ×1