检测Ajax调用,ASP.net [英] Detect ajax call, ASP.net

查看:112
本文介绍了检测Ajax调用,ASP.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能检测如果一个请求是一个Ajax请求(jQuery的距离),上一ASP.net应用程序的服务器端。我不希望这样做?mypage.aspx this_is_ajax =真...

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...

恩。

$.get("mypage.aspx");

在服务器端我想要做某些事情的时候请求是一个Ajax请求......

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

谢谢!

推荐答案

ASP.NET MVC有很大的扩展,这个,那个做的工作与jQuery。它检查了它是这样的:

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

检查核心系列:

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

检查标题集合(确保其不为空):

Check the headers collection (ensuring its not null):

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

它做了它作为一个扩展方法,这样您就可以重新创建它,或者用它,如果你是通过 Request.IsAjaxRequest使用ASP.NET MVC()

这篇关于检测Ajax调用,ASP.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆