简体   繁体   English

asp.net mvc 3 ajax发布请求

[英]asp.net mvc 3 ajax post requests

hi i'm creating an application that will track when a user send a post request. 嗨,我正在创建一个应用程序,它将跟踪用户何时发送发布请求。 once it has the certain number of post requests it will redirect to another page is. 一旦具有一定数量的发布请求,它将重定向到另一个页面。 I know that i will need to make an ajax function and that it will have to be on a loop to keep checking if the post have arrived but sure how this is done. 我知道我将需要做一个ajax函数,它必须处于循环状态以继续检查帖子是否已到达,但请确定如何完成。

if anyone can help with this or at least point me in the right direction thanks. 如果有人可以提供帮助,或者至少指出正确的方向,谢谢。

You could use the window.setInterval function to execute some function at regular intervals: 您可以使用window.setInterval函数定期执行一些函数:

window.setInterval(function() {
    // this will run every second
    if (user reached POST limit) {
        // redirect him somewhere
        window.location.href = 'http://www.google.com';
    }
}, 1000);

or if you are tracking the number of POST requests as I showed you here : 或者,如果您要跟踪我在此处显示的POST请求的数量,请执行以下操作:

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) {
            window.location.href = 'http://www.google.com';
            return false;
        }
    }
});

If all you are doing is logging HTTP posts as they enter the web server you can do the following: 如果您要做的只是记录HTTP帖子进入Web服务器时的记录,则可以执行以下操作:

1 Check cookies to see if this is a repeat request If cookie meets your criteria, then redirect to different page. 1检查cookie以查看是否重复请求,如果cookie符合您的条件,则重定向到其他页面。 You might want to clear or reset the cookie at that time, as I suspect you might want to log at that entry point as well 2 Log the action 您可能当时想清除或重置cookie,因为我怀疑您可能也想在该入口点登录2。

This does not need to be an Ajax request but it can be. 这不必是Ajax请求,但可以是。 To the web server, a request is a request. 对于Web服务器,请求就是请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM