开发者

Detect ajax call, ASP.net

开发者 https://www.devze.com 2023-01-10 16:21 出处:网络
how can I detect if a request is an AJAX-request (from jQuery) on the server-side of a ASP.net application. I don´t want to do this: mypage.aspx?this_is_ajax=true...

how can I detect if a request is an AJAX-request (from jQuery) on the server-side of a ASP.net application. I don´t want to do this: mypage.aspx?this_is_ajax=true...

ex.

开发者_如何学运维$.get("mypage.aspx");

On the server side I want to do certain things when the request is a ajax request...

Thanks!


ASP.NET MVC had a great extension for this, that did work with JQuery. It checked it this way:

Check the core collection:

request["X-Requested-With"] == "XMLHttpRequest"

Check the headers collection (ensuring its not null):

request.Headers["X-Requested-With"] == "XMLHttpRequest"

It did it as an extension method, so you could recreate it, or use it if you are using ASP.NET MVC through Request.IsAjaxRequest().

0

精彩评论

暂无评论...
验证码 换一张
取 消