c# - 在 asp.net mvc 3 和 jquery 中记录帖子

标签 c# jquery asp.net-mvc-3 http-post

您好,我是 ASP 和 jQuery 的新手,需要一些帮助。我想使用 Ajax 请求来记录发送请求的次数,但不知道从哪里开始。我认为这可能与 jQuery.ajaxSetup 有关,但不确定。

如果有人可以提供帮助或至少为我指出正确的方向,那就太好了。

最佳答案

您可以使用 beforeSend 回调:

var count = 0;

$.ajaxSetup({
    beforeSend: function(jqXHR, settings) {
        if (settings.type == 'POST') {
            count++;
        }

        // Allow only 3 POST AJAX requests for this page 
        // and if there are more abort them
        if (count > 3) {
            return false;
        }
    }
});

关于c# - 在 asp.net mvc 3 和 jquery 中记录帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11972037/

相关文章:

asp.net-mvc - 在单声道或 Windows 上托管 ServiceStack、MVC3 或 MVC4 以及单声道的状态是什么

c# - 找不到 WebClient

c# - 从 C# 应用程序调用 C++ 代码或移植它?

asp.net - 在MVC View 中从模型访问displayName属性

javascript - 设置媒体后无法在 jPlayer 中更改歌曲

javascript - 选择按类和属性选择的元素的邻居

c# - 将一个简单的字符串从 Controller 传递到 View MVC3

c# - 如何将 Telerik 网格设置为允许垂直滚动

c# - Visual Studio : generating code upon xsd problems with integers

javascript - 如何创建垂直图像滚动条?