小编use*_*173的帖子

ajaxComplete,XMLHttpRequest未定义

我有一个全局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,错误消失了.感谢波阿斯.

ajax jquery jquery-1.9

7
推荐指数
1
解决办法
2172
查看次数

将List <byte []>转换为一个byte []数组

如何List<byte[]>在一个byte[]数组或一个数组中进行转换Stream

.net c#

6
推荐指数
2
解决办法
3万
查看次数

在地址栏中隐藏传递给控制器​​的参数(URL 重写或其他内容)

我有以下路线:

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)

asp.net-mvc asp.net-mvc-3

6
推荐指数
1
解决办法
2万
查看次数

EF.连接没有关闭.连接的当前状态是连接

我有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

6
推荐指数
1
解决办法
9495
查看次数

为什么 Request.IsAuthenticated 是假的

我有以下脚本:

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)

asp.net-mvc

5
推荐指数
1
解决办法
4343
查看次数

在datePicker中获取选定的值并对其进行格式化

在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
如何正确格式化?
谢谢.

jquery jquery-ui datepicker

5
推荐指数
1
解决办法
10万
查看次数

通过css属性查找元素

我有一个div包含大约100个其他div元素.每个div元素都有topleft属性.如何找到div具有最大left属性的?
我需要最好的表现.谢谢.

jquery

5
推荐指数
1
解决办法
2754
查看次数

按名称的一部分查找数据属性

如何通过名称的一部分获取数据属性的值?
例如:

<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-emaildata-pcp-order

javascript jquery

5
推荐指数
1
解决办法
499
查看次数

延迟jquery承诺

我无法找到delaywait履行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)

jquery promise jquery-deferred

5
推荐指数
1
解决办法
3111
查看次数

包装所有回复

我想包装所有的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)

c# asp.net-core-mvc asp.net-core asp.net5

5
推荐指数
1
解决办法
1119
查看次数