record post in asp.net mvc 3 and jquery

狂风中的少年 提交于 2019-12-12 17:10:08

问题


Hi I'm quite new to ASP and jQuery and could do with some help. I want to use an Ajax request to record the number of times a post request is sent, but haven't got a clue where to start. I thought it might be something to do with an jQuery.ajaxSetup but am unsure.

If anyone could help or a least point me in the right direction that would be great.


回答1:


You could use the beforeSend callback:

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;
        }
    }
});



回答2:


You could do this on the client side with a cookie. Otherwise you could do this server side with a session variable.

There are examples of both on here.

How set Session variables in ASP.NET MVC 3 with jQuery?



来源:https://stackoverflow.com/questions/11972037/record-post-in-asp-net-mvc-3-and-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!