问题
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